Class: NilClass

Inherits:
Object
  • Object
show all
Defined in:
lib/common/class_exts/nilclass.rb

Overview

Carve out from lich.rbw extension to class Nilclass 2024-06-13

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*_args) ⇒ NilClass

Handles calls to methods that do not exist on the nil object.

Examples:

nil.some_non_existent_method # => nil

Parameters:

  • _args (Array)

    arguments passed to the missing method.

Returns:



22
23
24
# File 'lib/common/class_exts/nilclass.rb', line 22

def method_missing(*_args)
  nil
end

Instance Method Details

#+(val) ⇒ Object

Adds a value to the nil object.

Examples:

nil + 5 # => 5

Parameters:

  • val (Object)

    the value to add.

Returns:

  • (Object)

    returns the value passed in.



64
65
66
# File 'lib/common/class_exts/nilclass.rb', line 64

def +(val)
  val
end

#closed?Boolean

Checks if the nil object is closed.

Examples:

nil.closed? # => true

Returns:

  • (Boolean)

    always returns true.



74
75
76
# File 'lib/common/class_exts/nilclass.rb', line 74

def closed?
  true
end

#dupNilClass

Duplicates the nil object.

Examples:

nil.dup # => nil

Returns:



11
12
13
# File 'lib/common/class_exts/nilclass.rb', line 11

def dup
  nil
end

#split(*_val) ⇒ Array

Splits the nil object into an array.

Examples:

nil.split # => []

Parameters:

  • _val (Array)

    optional parameters for splitting.

Returns:

  • (Array)

    returns an empty array.



33
34
35
# File 'lib/common/class_exts/nilclass.rb', line 33

def split(*_val)
  Array.new
end

#stripString

Removes whitespace from the nil object.

Examples:

nil.strip # => ""

Returns:

  • (String)

    returns an empty string.



53
54
55
# File 'lib/common/class_exts/nilclass.rb', line 53

def strip
  ""
end

#to_sString

Converts the nil object to a string.

Examples:

nil.to_s # => ""

Returns:

  • (String)

    returns an empty string.



43
44
45
# File 'lib/common/class_exts/nilclass.rb', line 43

def to_s
  ""
end