Ruby hash value truthiness and symbols
- by John Topley
Could somebody please explain why the variable named foo remains true in the code below, even though it's set to false when the method is called? And why the symbol version behaves as expected?
def test(options = {})
foo = options[:foo] || true
bar = options[:bar] || :true
puts "foo is #{foo}, bar is #{bar}"
end
>> test(:foo => false, :bar => :false)
foo is true, bar is false
I've only tried this using Ruby 1.8.7.