Class: Rewrite::ByExample::BindSequence
- Defined in:
- lib/rewrite/by_example/bind_sequence.rb
Overview
Matches any sequence of zero or more entities and binds the list to a name in the unfolded result. BindSequence.new(‘name’) binds whatever sequence of entities it matches to ‘name’.
Not isomorphic to AnyEntity: AnyEntity matches one entity, BindSequence matches a sequence of entities. If you want to match a single entity that happens to consist
LengthOne.new(Bind.new('name), AnyEntity.new)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#unfolder_lambda ⇒ Object
readonly
Returns the value of attribute unfolder_lambda.
Instance Method Summary collapse
- #fold(enum_of_bindings) ⇒ Object
-
#initialize(name) ⇒ BindSequence
constructor
A new instance of BindSequence.
- #length_range ⇒ Object
- #to_s ⇒ Object
- #unfolders_by_length(length) ⇒ Object
Constructor Details
#initialize(name) ⇒ BindSequence
Returns a new instance of BindSequence.
21 22 23 24 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 21 def initialize(name) @name = name.to_sym @unfolder_lambda = lambda { |arr| { @name => s(*arr) } } end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 19 def name @name end |
#unfolder_lambda ⇒ Object (readonly)
Returns the value of attribute unfolder_lambda.
19 20 21 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 19 def unfolder_lambda @unfolder_lambda end |
Instance Method Details
#fold(enum_of_bindings) ⇒ Object
34 35 36 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 34 def fold(enum_of_bindings) enum_of_bindings[name] end |
#length_range ⇒ Object
30 31 32 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 30 def length_range 0..10000 end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 38 def to_s "__* => #{name.inspect}" end |
#unfolders_by_length(length) ⇒ Object
26 27 28 |
# File 'lib/rewrite/by_example/bind_sequence.rb', line 26 def unfolders_by_length(length) [ unfolder_lambda ] end |