Class: Utils::IRB::Shell::WrapperBase
- Includes:
- Comparable
- Defined in:
- lib/utils/irb/shell/wrappers.rb
Overview
Base class for wrapping objects with descriptive metadata.
This class provides a foundation for creating wrapper objects that associate descriptive information with underlying objects. It handles name conversion and provides common methods for accessing and comparing wrapped objects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ String?
(also: #to_str, #inspect, #to_s)
readonly
The description reader method provides access to the description attribute.
-
#name ⇒ String
readonly
The name reader method returns the value of the name instance variable.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
The <=> method compares the names of two objects for sorting purposes.
-
#==(name) ⇒ Object
(also: #eql?)
The == method assigns a new name value to the instance variable.
-
#hash ⇒ Integer
The hash method returns the hash value of the name attribute.
-
#initialize(name) ⇒ WrapperBase
constructor
The initialize method sets up the instance name by converting the input to a string representation.
Constructor Details
#initialize(name) ⇒ WrapperBase
The initialize method sets up the instance name by converting the input to a string representation.
This method handles different input types by converting them to a string, prioritizing to_str over to_sym and falling back to to_s if neither is available.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/utils/irb/shell/wrappers.rb', line 19 def initialize(name) @name = case when name.respond_to?(:to_str) name.to_str when name.respond_to?(:to_sym) name.to_sym.to_s else name.to_s end end |
Instance Attribute Details
#description ⇒ String? (readonly) Also known as: to_str, inspect, to_s
The description reader method provides access to the description attribute.
41 42 43 |
# File 'lib/utils/irb/shell/wrappers.rb', line 41 def description @description end |
#name ⇒ String (readonly)
The name reader method returns the value of the name instance variable.
35 36 37 |
# File 'lib/utils/irb/shell/wrappers.rb', line 35 def name @name end |
Instance Method Details
#<=>(other) ⇒ Integer
The <=> method compares the names of two objects for sorting purposes.
73 74 75 |
# File 'lib/utils/irb/shell/wrappers.rb', line 73 def <=>(other) @name <=> other.name end |
#==(name) ⇒ Object Also known as: eql?
The == method assigns a new name value to the instance variable.
54 55 56 |
# File 'lib/utils/irb/shell/wrappers.rb', line 54 def ==(name) @name = name end |
#hash ⇒ Integer
The hash method returns the hash value of the name attribute.
63 64 65 |
# File 'lib/utils/irb/shell/wrappers.rb', line 63 def hash @name.hash end |