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 (also: #eql?)
- #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 Also known as: eql?
28 29 30 |
# File 'lib/thomas_utils/key_comparer.rb', line 28 def ==(rhs) rhs.is_a?(KeyComparer) && key == rhs.key && comparer == rhs.comparer end |
#hash ⇒ Object
33 34 35 |
# File 'lib/thomas_utils/key_comparer.rb', line 33 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 |