Class: SleepingKingStudios::Tools::Undefined

Inherits:
BasicObject
Defined in:
lib/sleeping_king_studios/tools/undefined.rb

Overview

Immutable empty object used to represent undefined method parameters.

Use an instance of Undefined as a value object to distinguish between an optional method parameter that is passed a nil value from a method parameter that is not passed.

Examples:

UNDEFINED = Undefined.new
private_constant :UNDEFINED

def parameter_passed?(parameter = UNDEFINED)
  parameter != UNDEFINED
end

parameter_passed?      #=> false
parameter_passed?(nil) #=> true

Instance Method Summary collapse

Instance Method Details

#inspectString

Returns a string containing a human-readable representation of the object.

Returns:

  • (String)

    a string containing a human-readable representation of the object.



25
26
27
# File 'lib/sleeping_king_studios/tools/undefined.rb', line 25

def inspect
  ::Object.instance_method(:inspect).bind(self).call
end

#instance_of?(mod) ⇒ true, false

Returns true if the object is an instance of the given class.

Parameters:

  • mod (Module)

    the class or module to compare.

Returns:

  • (true, false)

    true if the object is an instance of the given class.



33
34
35
# File 'lib/sleeping_king_studios/tools/undefined.rb', line 33

def instance_of?(mod)
  ::Object.instance_method(:instance_of?).bind(self).call(mod)
end

#is_a?(mod) ⇒ true, false Also known as: kind_of?

Returns true if the given class is an ancestor of the object.

Parameters:

  • mod (Module)

    the class or module to compare.

Returns:

  • (true, false)

    true if the given class is an ancestor of the object.



41
42
43
# File 'lib/sleeping_king_studios/tools/undefined.rb', line 41

def is_a?(mod)
  ::Object.instance_method(:is_a?).bind(self).call(mod)
end