Class: Squeeze::Matcher
- Inherits:
-
Object
- Object
- Squeeze::Matcher
- Defined in:
- lib/squeeze/matcher.rb
Overview
Matchers are initialized with a pattern, to be used for retrieval in a HashTree. What makes Matcher special, really the only reason it exists, is that it overrides #eql? and #hash so that Hashes will treat two Matchers as the same object if their patterns are the same. This prevents redundancy when a HashTree creates its internal tree.
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #call(val) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(pattern) ⇒ Matcher
constructor
A new instance of Matcher.
Constructor Details
#initialize(pattern) ⇒ Matcher
Returns a new instance of Matcher.
11 12 13 |
# File 'lib/squeeze/matcher.rb', line 11 def initialize(pattern) @pattern = pattern || true end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
10 11 12 |
# File 'lib/squeeze/matcher.rb', line 10 def pattern @pattern end |
Instance Method Details
#call(val) ⇒ Object
15 16 17 |
# File 'lib/squeeze/matcher.rb', line 15 def call(val) @pattern == val || @pattern == true end |
#eql?(other) ⇒ Boolean
19 20 21 |
# File 'lib/squeeze/matcher.rb', line 19 def eql?(other) other.kind_of?(self.class) && other.pattern == @pattern end |
#hash ⇒ Object
23 24 25 |
# File 'lib/squeeze/matcher.rb', line 23 def hash @pattern.hash end |