News for hackers. Stuff that matters.
Re:Ruby’s Most Underused Keyword by old-gregg on Friday February 06, 2009 @07:44PM (#470640)
My personal up until recently underused keyword was (surprise!) "rescue".

I'm not sure how this has been escaping me since 07, but I had no idea you can apply it at the end of an expression, i.e. when you're facing nasty functions that insist on trhowing exceptions, instead of

begin

  value = function_that_throws
rescue

  value = "default"
end

you can just write:

value = function_that_throws rescue "default"

Re:Ruby’s Most Underused Keyword by sc on Friday February 06, 2009 @08:03PM (#470659)
Cool, sure, but blind rescues are as the crow flies to bugs: use them wisely, or use them _why-ly.
Re:Ruby’s Most Underused Keyword by iamwil on Saturday February 07, 2009 @12:00AM (#470808)
that's along the lines of using or for nil returns.

value = function_that_nils || "default"

I've found it makes code more succinct.

Re:Ruby’s Most Underused Keyword by old-gregg on Saturday February 07, 2009 @12:12AM (#470816)
Careful here: I've seen plenty of "Rubiomatic" bugs that look like this:

value = function_that_nils or "default"

... which results in nil assignment to value. Accidental confusion between || and 'or' is very common in Ruby world IMO, almost like famous == vs = in C.

Re:Ruby’s Most Underused Keyword by iamwil on Saturday February 07, 2009 @08:26AM (#471105)
Agreed. I think one is for statements (or) and the other one is for expressions (||), so they have different operational precedence, even though you could use them interchangeably, as long as you knew what got executed first.