Class: ThomasUtils::KeyComparer
- Inherits:
-
Object
- Object
- ThomasUtils::KeyComparer
- Defined in:
- lib/thomas_utils/key_comparer.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #==(rhs) ⇒ Object
- #eql?(rhs) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(key, comparer) ⇒ KeyComparer
constructor
A new instance of KeyComparer.
- #new_key(updated_key) ⇒ Object
- #quote(quote) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, comparer) ⇒ KeyComparer
Returns a new instance of KeyComparer.
6 7 8 9 |
# File 'lib/thomas_utils/key_comparer.rb', line 6 def initialize(key, comparer) @key = key @comparer = comparer end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/thomas_utils/key_comparer.rb', line 4 def key @key end |
Instance Method Details
#==(rhs) ⇒ Object
28 29 30 |
# File 'lib/thomas_utils/key_comparer.rb', line 28 def ==(rhs) to_s == rhs.to_s end |
#eql?(rhs) ⇒ Boolean
32 33 34 |
# File 'lib/thomas_utils/key_comparer.rb', line 32 def eql?(rhs) self == rhs end |
#hash ⇒ Object
36 37 38 |
# File 'lib/thomas_utils/key_comparer.rb', line 36 def hash to_s.hash end |
#new_key(updated_key) ⇒ Object
11 12 13 |
# File 'lib/thomas_utils/key_comparer.rb', line 11 def new_key(updated_key) KeyComparer.new(updated_key, @comparer) end |
#quote(quote) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/thomas_utils/key_comparer.rb', line 15 def quote(quote) quoted_key = if key.respond_to?(:quote) key.quote(quote) else "#{quote}#{key}#{quote}" end "#{quoted_key} #{@comparer}" end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/thomas_utils/key_comparer.rb', line 24 def to_s "#{pretty_key} #{@comparer}" end |