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)]
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
The child to match.
Attributes inherited from Sexp
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, #find_and_replace_all, #find_node, #find_nodes, from_array, #gsub, include, #line_max, m, #map, #mass, #method_missing, #new, not?, #replace_sexp, #respond_to?, s, #search_each, #sexp_body, #sexp_body=, #sexp_type, #sexp_type=, #shift, #structure, #sub, t, #to_a
Constructor Details
#initialize(child) ⇒ Child
Create a Child matcher which will match anything having a descendant matching child
.
1100 1101 1102 |
# File 'lib/sexp.rb', line 1100 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.
1094 1095 1096 |
# File 'lib/sexp.rb', line 1094 def child @child end |
Instance Method Details
#==(o) ⇒ Object
:nodoc:
1116 1117 1118 |
# File 'lib/sexp.rb', line 1116 def == o # :nodoc: super && self.child == o.child end |
#inspect ⇒ Object
:nodoc:
1120 1121 1122 |
# File 'lib/sexp.rb', line 1120 def inspect # :nodoc: "child(%p)" % [child] end |
#pretty_print(q) ⇒ Object
:nodoc:
1124 1125 1126 1127 1128 |
# File 'lib/sexp.rb', line 1124 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
.
1108 1109 1110 1111 1112 1113 1114 |
# File 'lib/sexp.rb', line 1108 def satisfy? o if child.satisfy? o true elsif o.kind_of? Sexp o.search_each(child).any? end end |