class Sexp::Pattern

Matches any atom who’s string representation matches the patterns passed in.

examples:

s(:a) / s{ m('a') }                                      #=> [s(:a)]
s(:a) / s{ m(/\w/,/\d/) }                                #=> [s(:a)]
s(:tests, s(s(:test_a), s(:test_b))) / s{ m(/test_\w/) } #=> [s(:test_a),

TODO: maybe don’t require non-sexps? This does respond to =~ now.

Attributes

pattern[R]

The regexp to match for the pattern.

Public Class Methods

new(pattern) click to toggle source

Create a Patten matcher which will match any atom that either matches the input pattern.

# File lib/sexp_matcher.rb, line 834
def initialize pattern
  @pattern = pattern
end

Public Instance Methods

eql?(o) click to toggle source
Calls superclass method Sexp#eql?
# File lib/sexp_matcher.rb, line 855
def eql? o
  super and self.pattern.eql? o.pattern
end
hash() click to toggle source
Calls superclass method Sexp#hash
# File lib/sexp_matcher.rb, line 859
def hash
  [super, pattern].hash
end
satisfy?(o) click to toggle source

Satisfied if o is an atom, and o matches pattern

# File lib/sexp_matcher.rb, line 841
def satisfy? o
  !o.kind_of?(Sexp) && o.to_s =~ pattern # TODO: question to_s
end