Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > shorthand

Reply
Thread Tools

shorthand

 
 
Robert Klemme
Guest
Posts: n/a
 
      06-18-2010
2010/6/14 Roger Pack <>:
> I read this once:
>
> Operator ||=3D can be shorthand for code like:
> =A0x =3D "(some fallback value)" unless respond_to? or x
>
> How would that look like exactly, in shorthand, any guesses?


You can do this:

x ||=3D (x() rescue "(some fallback value)")

I did not think about this long enough to look at all the effects with
local variables shadowing methods but it's something you can play
with.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any() and all() shorthand castironpi@gmail.com Python 7 01-08-2008 04:26 AM
Shorthand for Property declaration in VB David W ASP .Net 0 01-17-2007 07:44 PM
Shorthand for namespaces Foxpointe XML 4 10-31-2006 09:41 PM
foreach shorthand unspammable@gmail.com C++ 2 03-25-2005 10:38 PM
kiwi biz q_'n <== Teeline shorthand for question Quean Computer Support 2 12-23-2004 07:08 AM



Advertisments