Class: NilClass
- Defined in:
- lib/more/facets/openobject.rb,
lib/core/facets/boolean.rb,
lib/more/facets/pathname.rb,
lib/core/facets/conversion.rb,
lib/core/facets/kernel/ergo.rb,
lib/core/facets/nilclass/status.rb
Overview
Core Extensions
Instance Method Summary collapse
-
#ergo ⇒ Object
Compliments Kernel#ergo.
-
#status(status = nil) ⇒ Object
Nil#status makes it possible to pass messages through a “failure” chain.
-
#status? ⇒ Boolean
Check status.
- #to_bool ⇒ Object
-
#to_f ⇒ Object
Allows
nilto respond to #to_f. -
#to_h ⇒ Object
Allows
nilto create an empty hash, similar to #to_a and #to_s. -
#to_openobject ⇒ Object
Nil converts to an empty OpenObject.
-
#to_path ⇒ Object
Provide platform dependent null path.
Instance Method Details
#ergo ⇒ Object
Compliments Kernel#ergo.
"a".ergo{ |o| o.upcase } #=> "A"
nil.ergo{ |o| o.bar } #=> nil
CREDIT: Daniel DeLorme
36 37 38 39 |
# File 'lib/core/facets/kernel/ergo.rb', line 36 def ergo @_ergo ||= Functor.new{ nil } @_ergo unless block_given? end |
#status(status = nil) ⇒ Object
Nil#status makes it possible to pass messages through a “failure” chain.
def foo
return nil.status("failed foo!")
end
result = foo
if result.nil?
result.status? #=> true
result.status #=> "failed foo!"
end
CREDIT: Trans
18 19 20 21 22 23 24 25 |
# File 'lib/core/facets/nilclass/status.rb', line 18 def status(status=nil) if status @status = status self else @status end end |
#status? ⇒ Boolean
Check status.
def foo
return nil.status("failed foo!")
end
result = foo
if result.nil?
result.status? #=> true
result.status #=> "failed foo!"
end
CREDIT: Trans
41 42 43 44 45 |
# File 'lib/core/facets/nilclass/status.rb', line 41 def status? return unless @status return false if @status.empty? return true end |
#to_bool ⇒ Object
158 159 160 |
# File 'lib/core/facets/boolean.rb', line 158 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
220 |
# File 'lib/core/facets/conversion.rb', line 220 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
231 |
# File 'lib/core/facets/conversion.rb', line 231 def to_h; {}; end |
#to_openobject ⇒ Object
Nil converts to an empty OpenObject.
207 208 209 |
# File 'lib/more/facets/openobject.rb', line 207 def to_openobject OpenObject.new end |