Created
January 31, 2021 07:42
-
-
Save baweaver/6d128bd9cc83bba0f712bc65abae6326 to your computer and use it in GitHub Desktop.
Quick Pattern Matching interface demonstration
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 'matchable' | |
class Person | |
include Matchable | |
deconstruct :new | |
deconstruct_keys :name, :age | |
attr_reader :name, :age | |
def initialize(name, age) | |
@name = name | |
@age = age | |
end | |
end | |
alice = Person.new('Alice', 42) | |
alice in Person[/^A/, 30..] | |
# => true | |
alice in { name: /^A/, age: 30.. } | |
# => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment