Skip to content

Instantly share code, notes, and snippets.

@bolshakov
Last active March 16, 2019 11:30
Show Gist options
  • Save bolshakov/ca1d480a0a5bdf46579794c6d4dcd639 to your computer and use it in GitHub Desktop.
Save bolshakov/ca1d480a0a5bdf46579794c6d4dcd639 to your computer and use it in GitHub Desktop.
destructing_struct
require 'fear'
User = Struct.new(:id, :name, :admin)
Fear.register_extractor(User, Fear.case(User, &:to_a).lift)
matcher = Fear.matcher do |m|
m.xcase('User(_, name, true)') do |name:|
puts "Hi #{name}, you are welcome"
end
m.xcase('User(_, _, false)') do
puts 'Only admins allowed here'
end
end
matcher.call User.new(1, 'Jane', true)
matcher.call User.new(1, 'John', false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment