Class: Sexp::All

Inherits:
Matcher show all
Defined in:
lib/sexp.rb

Overview

Matches only when all sub-expressions match.

This is also available via Matcher#&.

examples:

s(:a)     / s{ all(s(:a), s(:b)) }    #=> []
s(:a, :b) / s{ t(:a) & include(:b)) } #=> [s(:a, :b)]

Instance Attribute Summary collapse

Attributes inherited from Sexp

#comments, #file, #line

Instance Method Summary collapse

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(*options) ⇒ All

Create an All matcher which will match all of the options.



1002
1003
1004
# File 'lib/sexp.rb', line 1002

def initialize *options
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sexp

Instance Attribute Details

#optionsObject (readonly)

The collection of sub-matchers to match against.



997
998
999
# File 'lib/sexp.rb', line 997

def options
  @options
end

Instance Method Details

#==(o) ⇒ Object

:nodoc:



1015
1016
1017
# File 'lib/sexp.rb', line 1015

def == o # :nodoc:
  super && self.options == o.options
end

#inspectObject

:nodoc:



1019
1020
1021
# File 'lib/sexp.rb', line 1019

def inspect # :nodoc:
  options.map(&:inspect).join(" & ")
end

#pretty_print(q) ⇒ Object

:nodoc:



1023
1024
1025
1026
1027
1028
1029
# File 'lib/sexp.rb', line 1023

def pretty_print q # :nodoc:
  q.group 1, "all(", ")" do
    q.seplist options do |v|
      q.pp v
    end
  end
end

#satisfy?(o) ⇒ Boolean

Satisfied when all sub expressions match o

Returns:

  • (Boolean)


1009
1010
1011
1012
1013
# File 'lib/sexp.rb', line 1009

def satisfy? o
  options.all? { |exp|
    exp.kind_of?(Sexp) ? exp.satisfy?(o) : exp == o
  }
end