Module: Deterministic::PatternMatching

Defined in:
lib/deterministic/match.rb

Defined Under Namespace

Modules: Match Classes: NoMatchError

Instance Method Summary collapse

Instance Method Details

#match(context = nil, &block) ⇒ Object



5
6
7
8
9
10
# File 'lib/deterministic/match.rb', line 5

def match(context=nil, &block)
  context ||= block.binding.eval('self') # the instance containing the match block
  match = binding.eval('self.class::Match.new(self, context)') # the class defining the Match
  match.instance_eval &block
  match.call
end