Module: PatternMatchable

Defined in:
lib/pattern_matchable.rb,
lib/pattern_matchable/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.const_missing(klass_name) ⇒ Object



24
25
26
# File 'lib/pattern_matchable.rb', line 24

def self.const_missing(klass_name)
  self.refining(Object.const_get(klass_name))
end

.refining(klass) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pattern_matchable.rb', line 12

def self.refining(klass)
  Module.new {
    refine klass do
      include PatternMatchable
    end

    define_singleton_method(:const_missing) { |nested_name|
      PatternMatchable.refining Object.const_get("#{klass.name}::#{nested_name}")
    }
  }
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



4
5
6
# File 'lib/pattern_matchable.rb', line 4

def deconstruct_keys(keys)
  keys.to_h { [_1, public_send(_1)] }
end