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)]

Constant Summary

Constants inherited from Sexp

UNASSIGNED

Instance Attribute Summary collapse

Attributes inherited from Sexp

#comments, #file, #line, #line_max

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, #eql?, #find_and_replace_all, #find_node, #find_nodes, from_array, #gsub, #hash, include, k, m, #map, #mass, #method_missing, #new, not?, q, #replace_sexp, #respond_to?, s, #search_each, #sexp_body, #sexp_body=, #sexp_type, #sexp_type=, #shift, #structure, #sub, t, #to_a

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

Dynamic Method Handling

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

Instance Attribute Details

#valueObject (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

#inspectObject

: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