Skip to content

Instantly share code, notes, and snippets.

@3014zhangshuo
Forked from havenwood/fallthrough.rb
Created August 5, 2020 01:45
Show Gist options
  • Save 3014zhangshuo/6311c6553ba76d2afec0a35d1f3d7ae7 to your computer and use it in GitHub Desktop.
Save 3014zhangshuo/6311c6553ba76d2afec0a35d1f3d7ae7 to your computer and use it in GitHub Desktop.
Fallthrough case statement in Ruby
value = :initial
catch :redo do
case value
when :initial
puts 'initial'
value = :changed
redo
when :changed
puts 'changed'
value = :omgwtfbbq
redo
else
puts 'got here'
end
end
# >> initial
# >> changed
# >> got here
# => nil
@3014zhangshuo
Copy link
Author

Not a good way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment