Class: Funkr::Matchers::SafeMatcher
Class Method Summary collapse
- .build_matchers(constructs) ⇒ Object
- .constructs ⇒ Object
-
.match_with(normal_form) {|m| ... } ⇒ Object
&block.
Instance Method Summary collapse
-
#initialize(match) ⇒ SafeMatcher
constructor
A new instance of SafeMatcher.
- #run_match ⇒ Object
Constructor Details
#initialize(match) ⇒ SafeMatcher
Returns a new instance of SafeMatcher.
8 9 10 11 12 |
# File 'lib/funkr/adt/matcher.rb', line 8 def initialize(match) @const, *@data = match @runner = nil @undefined = self.class.constructs.clone end |
Class Method Details
.build_matchers(constructs) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/funkr/adt/matcher.rb', line 14 def self.build_matchers(constructs) @constructs = constructs constructs.each do |c| name, *data = c define_method(name) do |&b| @undefined.delete(name) if @const == name then @runner = b end end end end |
.constructs ⇒ Object
27 |
# File 'lib/funkr/adt/matcher.rb', line 27 def self.constructs; @constructs; end |
.match_with(normal_form) {|m| ... } ⇒ Object
&block
29 30 31 32 33 |
# File 'lib/funkr/adt/matcher.rb', line 29 def self.match_with(normal_form) # &block m = self.new(normal_form) yield m m.run_match end |
Instance Method Details
#run_match ⇒ Object
35 36 37 38 39 40 |
# File 'lib/funkr/adt/matcher.rb', line 35 def run_match if @undefined.any? then raise "Incomplete match, missing : #{@undefined.join(" ")}" end @runner.call(*@data) end |