Class: Toys::UniqueKey
- Inherits:
-
Object
- Object
- Toys::UniqueKey
- Defined in:
- lib/toys/unique_key.rb
Overview
A named unique key, useful for Context keys or sentinels.
Each individual instance of this class is unique and not equal to any other instance, even if they have the same user-visible name.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ UniqueKey
constructor
Create a new UniqueKey.
-
#inspect ⇒ String
A user-visible name of this key.
-
#to_s ⇒ String
A user-visible name of this key.
Constructor Details
#initialize(name = nil) ⇒ UniqueKey
Create a new UniqueKey.
17 18 19 20 21 22 |
# File 'lib/toys/unique_key.rb', line 17 def initialize(name = nil) # Interpolated literals are frozen on Ruby 2.7 but not on 3.0+, so this # freeze is required despite what RuboCop's 2.7 target thinks. @name = name ? -name : "(unnamed unique key #{object_id})".freeze # rubocop:disable Style/RedundantFreeze freeze end |
Instance Method Details
#inspect ⇒ String
Returns a user-visible name of this key.
34 35 36 |
# File 'lib/toys/unique_key.rb', line 34 def inspect @name end |
#to_s ⇒ String
Returns a user-visible name of this key.
27 28 29 |
# File 'lib/toys/unique_key.rb', line 27 def to_s @name end |