Class: NilClass

Inherits:
Object show all
Defined in:
lib/core/facets/boolean.rb,
lib/core/facets/kernel/try.rb,
lib/core/facets/object/dup.rb,
lib/core/facets/kernel/ergo.rb,
lib/core/facets/kernel/blank.rb,
lib/standard/facets/ostruct/to_ostruct.rb

Constant Summary collapse

FUNCTOR =
Functor.new{ nil }

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/core/facets/kernel/blank.rb', line 44

def blank?
  true
end

#clone?Boolean

Returns:

  • (Boolean)

34
# File 'lib/core/facets/object/dup.rb', line 34

def clone? ; false ; end

#dup!Object

Since NilClass is immutable it cannot be duplicated. For this reason #try_dup returns self.

nil.dup!  #=> nil

32
# File 'lib/core/facets/object/dup.rb', line 32

def dup!   ; self  ; end

#dup?Boolean

Returns:

  • (Boolean)

33
# File 'lib/core/facets/object/dup.rb', line 33

def dup?   ; false ; end

#ergoObject

Compliments Kernel#ergo.

"a".ergo{ |o| o.upcase } #=> "A"
nil.ergo{ |o| o.bar }    #=> nil

CREDIT: Daniel DeLorme


38
39
40
# File 'lib/core/facets/kernel/ergo.rb', line 38

def ergo
  FUNCTOR unless block_given?
end

#to_boolObject


51
52
53
# File 'lib/core/facets/boolean.rb', line 51

def to_bool
  false
end

#to_ostructObject

Create an empty OpenStruct object.


61
62
63
# File 'lib/standard/facets/ostruct/to_ostruct.rb', line 61

def to_ostruct
  OpenStruct.new
end

#try(method = nil, *args) ⇒ Object

See Kernel#try.


49
50
51
52
53
54
55
# File 'lib/core/facets/kernel/try.rb', line 49

def try(method=nil, *args)
  if method
    nil
  else
    Functor.new{ nil }
  end
end