class Guaranteed::NullObject

An implementation the Null Object pattern.

Overrides some common Ruby and Rails methods to avoid continual

type-checking. Delegates most of them to an intance of NilClass.

Public Instance Methods

!() click to toggle source
# File lib/guaranteed/null_object.rb, line 33
def !
  true
end
as_json(options = nil) click to toggle source
# File lib/guaranteed/null_object.rb, line 37
def as_json(options = nil)
  nil
end
blank?() click to toggle source
# File lib/guaranteed/null_object.rb, line 25
def blank?
  true
end
empty?() click to toggle source
# File lib/guaranteed/null_object.rb, line 21
def empty?
  true
end
method_missing(method_name, *args, &block) click to toggle source

Allows instances of the class to respond to any received message.

Supports unlimited method chaining. Avoids NoMethodError in any

part of the method chain.
# File lib/guaranteed/null_object.rb, line 49
def method_missing(method_name, *args, &block)
  self
end
persisted?() click to toggle source
# File lib/guaranteed/null_object.rb, line 13
def persisted?
  false
end
present?() click to toggle source
# File lib/guaranteed/null_object.rb, line 17
def present?
  false
end
respond_to_missing?(method_name, include_private = false) click to toggle source
# File lib/guaranteed/null_object.rb, line 53
def respond_to_missing?(method_name, include_private = false)
  true
end
tap() click to toggle source
# File lib/guaranteed/null_object.rb, line 29
def tap
  self
end
to_json() click to toggle source
# File lib/guaranteed/null_object.rb, line 41
def to_json
  "null"
end

Private Instance Methods

value() click to toggle source
# File lib/guaranteed/null_object.rb, line 59
def value
  nil
end