Module: Quincunx::PatternMatcher

Defined in:
lib/quincunx/pattern_matcher.rb

Instance Method Summary collapse

Instance Method Details

#define(name, *args, &body) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/quincunx/pattern_matcher.rb', line 5

def define name, *args, &body
  cases = dictionary[name] << Method.new(args, body)
  define_method name do |*args, &block|
    cases.match(self, args).match do |m|
      m.some { |body| body.call }
      m.none { raise NoMatchForPatternError }
    end
  end
end