Class: Rewrite::ByExample::EntityMatcher
- Inherits:
-
Object
- Object
- Rewrite::ByExample::EntityMatcher
- Defined in:
- lib/rewrite/by_example/entity_matcher.rb
Overview
Matches a single something against a sexp such as an array or a literal symbol
Direct Known Subclasses
Instance Attribute Summary collapse
-
#predicate ⇒ Object
Returns the value of attribute predicate.
Instance Method Summary collapse
-
#after_unfold ⇒ Object
advice for unfold.
-
#fold(enum_of_bindings) ⇒ Object
takes an enumeration of bindings and returns nil or a sexp.
- #such_that!(&predicate_clause) ⇒ Object
-
#unfold(sexp) ⇒ Object
takes a sexp and returns nil or an enumeration of bindings, typically as a hash.
Instance Attribute Details
#predicate ⇒ Object
Returns the value of attribute predicate.
11 12 13 |
# File 'lib/rewrite/by_example/entity_matcher.rb', line 11 def predicate @predicate end |
Instance Method Details
#after_unfold ⇒ Object
advice for unfold
40 41 42 |
# File 'lib/rewrite/by_example/entity_matcher.rb', line 40 def after_unfold end |
#fold(enum_of_bindings) ⇒ Object
takes an enumeration of bindings and returns nil or a sexp.
Note the identity: if x.unfold(sexp) is not nil, then sexp == x.fold(x.unfold(sexp))
34 35 36 |
# File 'lib/rewrite/by_example/entity_matcher.rb', line 34 def fold(enum_of_bindings) raise 'implemented by includer' end |
#such_that!(&predicate_clause) ⇒ Object
13 14 15 16 |
# File 'lib/rewrite/by_example/entity_matcher.rb', line 13 def such_that!(&predicate_clause) self.predicate = predicate_clause self end |
#unfold(sexp) ⇒ Object
takes a sexp and returns nil or an enumeration of bindings, typically as a hash. Note that the empty hash is truthy, and this is what we want: it means a match that doesn’t perform any bindings
Note the identity: if x.fold(enum_of_bindings) is not nil, then enum_of_bindings == x.unfold(x.fold(enum_of_bindings))
25 26 27 |
# File 'lib/rewrite/by_example/entity_matcher.rb', line 25 def unfold(sexp) raise 'implemented by includer' end |