B
bwv549
Is there a way to access the variable being tossed through the
case/when structure?
case object.size.to_s
when /33/
# ...
when /44/
# ...
else
abort "Invalid variable: " + ???
# Is there a way to access the variable being tossed through
case/when?
# something like: $_, or $!
end
One can always do this:
x = object.size.to_s
case x
when /3ft/
when /4cm/
else
abort "Bad match: #{x}"
end
But it would save a line to be able to access the actual variable being
used in the case/when structure.
Thanks
case/when structure?
case object.size.to_s
when /33/
# ...
when /44/
# ...
else
abort "Invalid variable: " + ???
# Is there a way to access the variable being tossed through
case/when?
# something like: $_, or $!
end
One can always do this:
x = object.size.to_s
case x
when /3ft/
when /4cm/
else
abort "Bad match: #{x}"
end
But it would save a line to be able to access the actual variable being
used in the case/when structure.
Thanks