Ruby Arguments Can Reference Other Arguments
I love the dark corners of Ruby. Today we discovered this one by basically guessing that it might work:
def foos(foo, bar = foo.upcase + "!")
puts foo
puts bar
end
2.3.1 :001 > foos('foo')
foo
FOO!
=> nil
That's right; bar
references another argument, foo
. And we can also call a method on it. And concatenate it with a string, because, why not? The 'principle of least surprise' strikes again.
h/t Brian Dunn
Tweet