Class: Sexp::Not

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

Overview

Matches when sub-expression does not match.

This is also available via Matcher#-@.

examples:

s(:a) / s{ not?(s(:b)) } #=> [s(:a)]
s(:a) / s{ -s(:b) }      #=> [s(:a)]
s(:a) / s{ s(not? :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) ⇒ Not

Creates a Matcher which will match any Sexp that does not match the value



707
708
709
# File 'lib/sexp_matcher.rb', line 707

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 to negate in the match.



702
703
704
# File 'lib/sexp_matcher.rb', line 702

def value
  @value
end

Instance Method Details

#==(o) ⇒ Object

:nodoc:



711
712
713
# File 'lib/sexp_matcher.rb', line 711

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

#inspectObject

:nodoc:



722
723
724
# File 'lib/sexp_matcher.rb', line 722

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

#pretty_print(q) ⇒ Object

:nodoc:



726
727
728
729
730
# File 'lib/sexp_matcher.rb', line 726

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

#satisfy?(o) ⇒ Boolean

Satisfied if a o does not match the value

Returns:

  • (Boolean)


718
719
720
# File 'lib/sexp_matcher.rb', line 718

def satisfy? o
  !(value.kind_of?(Sexp) ? value.satisfy?(o) : value == o)
end