Class: NilClass
- Defined in:
- lib/active_support/whiny_nil.rb,
lib/active_support/core_ext/try.rb,
lib/active_support/core_ext/duplicable.rb,
lib/active_support/core_ext/object/blank.rb,
lib/active_support/json/encoders/nil_class.rb
Overview
:nodoc:
Constant Summary collapse
- WHINERS =
[::Array]
- METHOD_CLASS_MAP =
Hash.new
- AS_JSON =
ActiveSupport::JSON::Variable.new('null').freeze
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
- #blank? ⇒ Boolean
- #duplicable? ⇒ Boolean
-
#id ⇒ Object
Raises a RuntimeError when you attempt to call
id
onnil
. - #try(*args) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_support/whiny_nil.rb', line 45 def method_missing(method, *args, &block) # Ruby 1.9.2: disallow explicit coercion via method_missing. if method == :to_ary || method == :to_str super elsif klass = METHOD_CLASS_MAP[method] raise_nil_warning_for klass, method, caller else super end end |
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
4 5 6 |
# File 'lib/active_support/json/encoders/nil_class.rb', line 4 def as_json( = nil) #:nodoc: AS_JSON end |
#blank? ⇒ Boolean
41 42 43 |
# File 'lib/active_support/core_ext/object/blank.rb', line 41 def blank? true end |
#duplicable? ⇒ Boolean
10 11 12 |
# File 'lib/active_support/core_ext/duplicable.rb', line 10 def duplicable? false end |
#id ⇒ Object
Raises a RuntimeError when you attempt to call id
on nil
.
40 41 42 |
# File 'lib/active_support/whiny_nil.rb', line 40 def id raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller end |
#try(*args) ⇒ Object
33 34 35 |
# File 'lib/active_support/core_ext/try.rb', line 33 def try(*args) nil end |