module PatternMatch
Constants
- VERSION
Public Instance Methods
accept_self_instance_only(val)
click to toggle source
# File lib/pattern-match/deconstructor.rb, line 31 def accept_self_instance_only(val) raise PatternMatch::PatternNotMatch unless val.kind_of?(self) end
deconstruct(val)
click to toggle source
# File lib/pattern-match/deconstructor.rb, line 25 def deconstruct(val) raise NotImplementedError, "need to define `#{__method__}'" end
match(*vals, &block)
click to toggle source
# File lib/pattern-match/core.rb, line 636 def match(*vals, &block) do_match = Proc.new do |val| env = Env.new(self, val) catch(env) do env.instance_eval(&block) raise NoMatchingPatternError end end case vals.length when 0 do_match when 1 do_match.(vals[0]) else raise ArgumentError, "wrong number of arguments (#{vals.length} for 0..1)" end end
pattern_matcher(*subpatterns)
click to toggle source
# File lib/pattern-match/deconstructor.rb, line 7 def pattern_matcher(*subpatterns) PatternObjectDeconstructor.new(self, *subpatterns) end