Class: NilClass

Inherits:
Object show all
Defined in:
lib/gems/extlib-0.9.9/lib/extlib/blank.rb,
lib/gems/extlib-0.9.9/lib/extlib/nil.rb,
lib/mack-facets/extensions/nil_class.rb,
lib/gems/activesupport-2.2.2/lib/active_support/whiny_nil.rb,
lib/gems/activesupport-2.2.2/lib/active_support/core_ext/blank.rb,
lib/gems/activesupport-2.2.2/lib/active_support/core_ext/duplicable.rb,
lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/nil_class.rb

Overview

:nodoc:

Constant Summary collapse

WHINERS =
[::Array]
METHOD_CLASS_MAP =
Hash.new

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



45
46
47
# File 'lib/gems/activesupport-2.2.2/lib/active_support/whiny_nil.rb', line 45

def method_missing(method, *args, &block)
  raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
end

Instance Method Details

#blank?TrueClass

Nil is always blank

nil.blank?        #=>  true

Returns:



42
43
44
# File 'lib/gems/extlib-0.9.9/lib/extlib/blank.rb', line 42

def blank?
  true
end

#duplicable?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/duplicable.rb', line 10

def duplicable?
  false
end

#idObject

Raises a RuntimeError when you attempt to call id on nil.

Raises:

  • (RuntimeError)


40
41
42
# File 'lib/gems/activesupport-2.2.2/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

#to_json(options = nil) ⇒ Object

:nodoc:



2
3
4
# File 'lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/nil_class.rb', line 2

def to_json(options = nil) #:nodoc:
  'null'
end

#to_paramObject

Raises:

  • (NoMethodError)


3
4
5
# File 'lib/mack-facets/extensions/nil_class.rb', line 3

def to_param
  raise NoMethodError.new(:to_param)
end

#try_dupObject



2
3
4
# File 'lib/gems/extlib-0.9.9/lib/extlib/nil.rb', line 2

def try_dup
  self
end