Class: Sexp::Include

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

Overview

Matches an expression or any expression that includes the child.

examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#&, #-@, #/, #=~, #>>, #greedy?, match_subs=, match_subs?, parse, #|

Constructor Details

#initialize(value) ⇒ Include

Creates a Matcher which will match any Sexp that contains the value.



948
949
950
# File 'lib/sexp_matcher.rb', line 948

def initialize value
  @value = value
end

Instance Attribute Details

#value ⇒ Object (readonly)

The value that should be included in the match.



942
943
944
# File 'lib/sexp_matcher.rb', line 942

def value
  @value
end

Instance Method Details

#==(o) ⇒ Object

:nodoc:



963
964
965
# File 'lib/sexp_matcher.rb', line 963

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

#inspect ⇒ Object

:nodoc:



967
968
969
# File 'lib/sexp_matcher.rb', line 967

def inspect # :nodoc:
  "include(%p)" % [value]
end

#pretty_print(q) ⇒ Object

:nodoc:



971
972
973
974
975
# File 'lib/sexp_matcher.rb', line 971

def pretty_print q # :nodoc:
  q.group 1, "include(", ")" do
    q.pp value
  end
end

#satisfy?(o) ⇒ Boolean

Satisfied if a o is a Sexp and one of +o+'s elements matches value

Returns:

  • (Boolean)


956
957
958
959
960
961
# File 'lib/sexp_matcher.rb', line 956

def satisfy? o
  Sexp === o && o.any? { |c|
    # TODO: switch to respond_to??
    Sexp === value ? value.satisfy?(c) : value == c
  }
end