Class: Sexp::MatchCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/sexp.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



1400
1401
1402
1403
1404
# File 'lib/sexp.rb', line 1400

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

#inspectObject Also known as: to_s

:nodoc:



1406
1407
1408
# File 'lib/sexp.rb', line 1406

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

#pretty_print(q) ⇒ Object

:nodoc:



1412
1413
1414
1415
1416
# File 'lib/sexp.rb', line 1412

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