Class: NilClass
- Defined in:
- lib/core/facets/boolean.rb,
lib/core/facets/to_hash.rb,
lib/core/facets/kernel/try.rb,
lib/core/facets/object/dup.rb,
lib/core/facets/kernel/ergo.rb,
lib/standard/facets/ostruct.rb,
lib/core/facets/kernel/blank.rb,
lib/standard/facets/pathname.rb,
lib/core/facets/nilclass/to_f.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #clone? ⇒ Boolean
-
#dup! ⇒ Object
Since NilClass is immutable it cannot be duplicated.
- #dup? ⇒ Boolean
-
#ergo ⇒ Object
Compliments Kernel#ergo.
- #to_bool ⇒ Object
-
#to_f ⇒ Object
Allows
nil
to respond to #to_f. -
#to_h ⇒ Object
Allows
nil
to create an empty hash, similar to #to_a and #to_s. -
#to_ostruct ⇒ Object
Create an empty OpenStruct object.
-
#to_path ⇒ Object
Provide platform dependent null path.
-
#try(method = nil, *args) ⇒ Object
See Kernel#try.
Instance Method Details
#blank? ⇒ Boolean
44 45 46 |
# File 'lib/core/facets/kernel/blank.rb', line 44 def blank? true end |
#clone? ⇒ 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
33 |
# File 'lib/core/facets/object/dup.rb', line 33 def dup? ; false ; end |
#ergo ⇒ Object
Compliments Kernel#ergo.
"a".ergo{ |o| o.upcase } #=> "A"
nil.ergo{ |o| o. } #=> nil
CREDIT: Daniel DeLorme
37 38 39 40 |
# File 'lib/core/facets/kernel/ergo.rb', line 37 def ergo @_ergo ||= Functor.new{ nil } @_ergo unless block_given? end |
#to_bool ⇒ Object
51 52 53 |
# File 'lib/core/facets/boolean.rb', line 51 def to_bool false end |
#to_f ⇒ Object
Allows nil
to respond to #to_f. Always returns 0
.
nil.to_f #=> 0.0
CREDIT: Matz
12 |
# File 'lib/core/facets/nilclass/to_f.rb', line 12 def to_f; 0.0; end |
#to_h ⇒ Object
Allows nil
to create an empty hash, similar to #to_a and #to_s.
nil.to_h #=> {}
CREDIT: Trans
268 |
# File 'lib/core/facets/to_hash.rb', line 268 def to_h; {}; end |
#to_ostruct ⇒ Object
Create an empty OpenStruct object.
205 206 207 |
# File 'lib/standard/facets/ostruct.rb', line 205 def to_ostruct OpenStruct.new end |