Post tagged: wtf

Illogical or

'Or' or something else.

In which we consider the difference between or and || in Ruby. The secret is ... it depends. On context.

Behold:

>> foo = nil or "foo"
=> "foo"
>> bar = nil || "bar"
=> "bar"

That makes sense. But!:

def testor (&block)
   foo = block or "foo"
   bar = block || "bar"
   return foo, bar, block
end

>> testor()
=> [nil, "bar …

Ruby 1.9, keyword arguments, WTF

Amongst the many entries Ruby has in the "you have got to be kidding me" stakes, this is a doozy.

Due to Ruby's lack of explicit support for keyword arguments, it's traditional to use a quirk of its argument parsing that pushes named arguments into a hash:

def foo (a …