Class: NilClass

Inherits:
Object show all
Defined in:
lib/nano/nilclass/size.rb,
lib/nano/nilclass/to_f.rb,
lib/nano/nilclass/to_h.rb,
lib/nano/object/to_bool.rb,
lib/nano/nilclass/%5B%5D.rb,
lib/nano/nilclass/length.rb,
lib/nano/nilclass/empty%3F.rb,
lib/nano/nilclass/include%3F.rb,
lib/nano/nilclass/method_missing.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Have nil respond to all non-existent methods by always returning nil.

nil.foo   #=> nil


7
8
9
# File 'lib/nano/nilclass/method_missing.rb', line 7

def method_missing(meth, *args)
  nil
end

Instance Method Details

#[](*args) ⇒ Object

Allows nil to respond to #[]. Always returns nil.

nil[]   #=> nil


7
8
9
# File 'lib/nano/nilclass/%5B%5D.rb', line 7

def [](*args)
  nil
end

#empty?Boolean

Allows nil to respond to #empty? method. Alwasy returns true.

nil.empty?   #=> true

Returns:

  • (Boolean)


7
# File 'lib/nano/nilclass/empty%3F.rb', line 7

def empty? ; true ; end

#include?(*args) ⇒ Boolean

Allows nil to respond to #include? method. Alwasy returns nil.

nil.include?("abc")   #=> nil

Returns:

  • (Boolean)


7
# File 'lib/nano/nilclass/include%3F.rb', line 7

def include?(*args); nil; end

#lengthObject

Allows nil to respond to #length. Always returns 0.

nil.length   #=> 0


9
# File 'lib/nano/nilclass/length.rb', line 9

def length; 0; end

#sizeObject

Allows nil to respond to #size. Always returns 0.

nil.size   #=> 0


9
# File 'lib/nano/nilclass/size.rb', line 9

def size; 0; end

#to_boolObject



21
22
23
# File 'lib/nano/object/to_bool.rb', line 21

def to_bool
  false
end

#to_fObject

Returns zero float, similar to #to_i.

nil.to_f   #=> 0.0


7
# File 'lib/nano/nilclass/to_f.rb', line 7

def to_f; 0.0; end

#to_hObject

Allows nil to create an empty hash, similar to #to_a and #to_s.

nil.to_h    #=> {}


8
# File 'lib/nano/nilclass/to_h.rb', line 8

def to_h; {}; end