Class: SafeNil
Overview
Extending BasicObject because it provides us with a clean slate. It is similar to Object except it has almost all the standard methods stripped away so that we will hit method_missing for almost all method routing.
See NilClass#_?/Object#_?
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#method_missing(method, *args, &block) ⇒ Object
See NilClass#_?/Object#_?.
-
#nil? ⇒ Boolean
See NilClass#_?/Object#_?.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
See NilClass#_?/Object#_?
72 73 74 75 |
# File 'lib/quality_extensions/safe_nil.rb', line 72 def method_missing(method, *args, &block) return nil unless nil.respond_to?(method) # A much faster alternative to 'rescue nil' that can be used most of the time to speed things up. nil.send(method, *args, &block) rescue nil end |
Instance Method Details
#blank? ⇒ Boolean
79 |
# File 'lib/quality_extensions/safe_nil.rb', line 79 def blank?; true; end |
#nil? ⇒ Boolean
See NilClass#_?/Object#_?
78 |
# File 'lib/quality_extensions/safe_nil.rb', line 78 def nil?; true; end |