Class: Rewrite::ByExample::Bind
- Inherits:
-
EntityMatcher
- Object
- EntityMatcher
- Rewrite::ByExample::Bind
- Defined in:
- lib/rewrite/by_example/bind.rb
Overview
Abstract class that matches any entity and optionally binds that entity’s value to a name in the unfolded result. Useful for creating classes that bind and match simultaneously
Instance Attribute Summary collapse
-
#entity_matcher ⇒ Object
Returns the value of attribute entity_matcher.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from EntityMatcher
Instance Method Summary collapse
- #fold(enum_of_bindings) ⇒ Object
-
#initialize(name, entity_matcher) ⇒ Bind
constructor
A new instance of Bind.
- #to_s ⇒ Object
- #unfold(sexp) ⇒ Object
Methods inherited from EntityMatcher
Constructor Details
#initialize(name, entity_matcher) ⇒ Bind
Returns a new instance of Bind.
16 17 18 19 |
# File 'lib/rewrite/by_example/bind.rb', line 16 def initialize(name, entity_matcher) self.name = name.to_sym self.entity_matcher = entity_matcher end |
Instance Attribute Details
#entity_matcher ⇒ Object
Returns the value of attribute entity_matcher.
14 15 16 |
# File 'lib/rewrite/by_example/bind.rb', line 14 def entity_matcher @entity_matcher end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/rewrite/by_example/bind.rb', line 14 def name @name end |
Instance Method Details
#fold(enum_of_bindings) ⇒ Object
25 26 27 |
# File 'lib/rewrite/by_example/bind.rb', line 25 def fold (enum_of_bindings) enum_of_bindings[self.name] end |
#to_s ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rewrite/by_example/bind.rb', line 29 def to_s if name "#{entity_matcher.to_s} => #{name.inspect}" else '*' end end |
#unfold(sexp) ⇒ Object
21 22 23 |
# File 'lib/rewrite/by_example/bind.rb', line 21 def unfold (sexp) { self.name => sexp } if entity_matcher.unfold(sexp) end |