Class: Sexp::MatchCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/sexp_matcher.rb

Overview

Wraps the results of a Sexp query. MatchCollection defines MatchCollection#/ so that you can chain queries.

For instance:

res = s(:a, s(:b)) / s{ s(:a,_) } / s{ s(:b) }

Instance Method Summary collapse

Instance Method Details

#/(pattern) ⇒ Object

See Traverse#search



1082
1083
1084
1085
1086
# File 'lib/sexp_matcher.rb', line 1082

def / pattern
  inject(self.class.new) { |result, match|
    result.concat match / pattern
  }
end

#inspectObject Also known as: to_s

:nodoc:



1088
1089
1090
# File 'lib/sexp_matcher.rb', line 1088

def inspect # :nodoc:
  "MatchCollection.new(%s)" % self.to_a.inspect[1..-2]
end

#pretty_print(q) ⇒ Object

:nodoc:



1094
1095
1096
1097
1098
# File 'lib/sexp_matcher.rb', line 1094

def pretty_print q # :nodoc:
  q.group 1, "MatchCollection.new(", ")" do
    q.seplist(self) {|v| q.pp v }
  end
end