Skip to content

Instantly share code, notes, and snippets.

@baweaver
Created January 31, 2021 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baweaver/6d128bd9cc83bba0f712bc65abae6326 to your computer and use it in GitHub Desktop.
Save baweaver/6d128bd9cc83bba0f712bc65abae6326 to your computer and use it in GitHub Desktop.
Quick Pattern Matching interface demonstration
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