Class: Sexp::Child
Overview
Matches anything that has a child matching the sub-expression
example:
s(s(s(s(s(:a))))) / s{ child(s(:a)) } #=> [s(s(s(s(s(:a))))),
s(s(s(s(:a)))),
s(s(s(:a))),
s(s(:a)),
s(:a)]
Constant Summary
Constants inherited from Sexp
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
The child to match.
Attributes inherited from Sexp
#comments, #file, #line, #line_max
Instance Method Summary collapse
-
#==(o) ⇒ Object
:nodoc:.
-
#initialize(child) ⇒ Child
constructor
Create a Child matcher which will match anything having a descendant matching
child
. -
#inspect ⇒ Object
:nodoc:.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#satisfy?(o) ⇒ Boolean
Satisfied if matches
child
oro
has a descendant matchingchild
.
Methods inherited from Matcher
#&, #-@, #/, #=~, #>>, #greedy?, match_subs=, match_subs?, parse, #|
Methods inherited from Sexp
#/, #=~, _, ___, all, any, #array_type?, atom, child, #compact, #deep_each, #depth, #each_of_type, #each_sexp, #eql?, #find_and_replace_all, #find_node, #find_nodes, from_array, #gsub, #hash, include, k, m, #map, #mass, #method_missing, #new, not?, q, #replace_sexp, #respond_to?, s, #search_each, #sexp_body, #sexp_body=, #sexp_type, #sexp_type=, #shift, #structure, #sub, t, #to_a, #value
Constructor Details
#initialize(child) ⇒ Child
Create a Child matcher which will match anything having a descendant matching child
.
754 755 756 |
# File 'lib/sexp_matcher.rb', line 754 def initialize child @child = child end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sexp
Instance Attribute Details
#child ⇒ Object (readonly)
The child to match.
748 749 750 |
# File 'lib/sexp_matcher.rb', line 748 def child @child end |
Instance Method Details
#==(o) ⇒ Object
:nodoc:
767 768 769 |
# File 'lib/sexp_matcher.rb', line 767 def == o # :nodoc: super && self.child == o.child end |
#inspect ⇒ Object
:nodoc:
771 772 773 |
# File 'lib/sexp_matcher.rb', line 771 def inspect # :nodoc: "child(%p)" % [child] end |
#pretty_print(q) ⇒ Object
:nodoc:
775 776 777 778 779 |
# File 'lib/sexp_matcher.rb', line 775 def pretty_print q # :nodoc: q.group 1, "child(", ")" do q.pp child end end |
#satisfy?(o) ⇒ Boolean
Satisfied if matches child
or o
has a descendant matching child
.
762 763 764 765 |
# File 'lib/sexp_matcher.rb', line 762 def satisfy? o child.satisfy?(o) || (o.kind_of?(Sexp) && o.search_each(child).any?) end |