Last active
March 16, 2019 11:30
-
-
Save bolshakov/ca1d480a0a5bdf46579794c6d4dcd639 to your computer and use it in GitHub Desktop.
destructing_struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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