class Sexp::Pattern

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


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.



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

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
hash() click to toggle source
Calls superclass method Sexp#hash
# File lib/sexp_matcher.rb, line 859
def hash
  [super, pattern].hash
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