Class: Utils::IRB::Shell::WrapperBase

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/utils/irb.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

ConstantWrapper, MethodWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • name (Object)

    the input name to be converted to a string



301
302
303
304
305
306
307
308
309
310
311
# File 'lib/utils/irb.rb', line 301

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

#descriptionString? (readonly) Also known as: to_str, inspect, to_s

The description reader method provides access to the description attribute.

Returns:

  • (String, nil)

    the description value or nil if not set



323
324
325
# File 'lib/utils/irb.rb', line 323

def description
  @description
end

#nameString (readonly)

The name reader method returns the value of the name instance variable.

Returns:

  • (String)

    the value stored in the name instance variable



317
318
319
# File 'lib/utils/irb.rb', line 317

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Integer

The <=> method compares the names of two objects for sorting purposes.

Parameters:

  • other (Object)

    the other object to compare against

Returns:

  • (Integer)

    -1 if this object’s name is less than the other’s, 0 if they are equal, or 1 if this object’s name is greater than the other’s



355
356
357
# File 'lib/utils/irb.rb', line 355

def <=>(other)
  @name <=> other.name
end

#==(name) ⇒ Object Also known as: eql?

The == method assigns a new name value to the instance variable.

Parameters:

  • name (Object)

    the name value to be assigned

Returns:

  • (Object)

    returns the assigned name value



336
337
338
# File 'lib/utils/irb.rb', line 336

def ==(name)
  @name = name
end

#hashInteger

The hash method returns the hash value of the name attribute.

Returns:

  • (Integer)

    the hash value used for object identification



345
346
347
# File 'lib/utils/irb.rb', line 345

def hash
  @name.hash
end