In Ruby, is there a way to get the implicit object of a case statement?
case 2+2
when '2'
puts '2'
else
puts "#{some_object}"
end
Where 'some_object' would be the return value of whatever statement was evaluated by case
No there's not. You'll have to do something like:
some_object = 2+2
case some_object
when '2'
puts '2'
else
puts some_object
end
or
case some_object = 2+2
when '2'
puts '2'
else
puts some_object
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With