Class: NullChainer

Inherits:
BasicObject
Defined in:
lib/nullobject_chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ NullChainer

Returns a new instance of NullChainer.



2
3
4
# File 'lib/nullobject_chain.rb', line 2

def initialize(obj)
  @obj = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nullobject_chain.rb', line 10

def method_missing(name, *args, &block)
  begin
    ::NullChainer.new(@obj.send(name, *args, &block)) 
  rescue ::NoMethodError
    if @obj.nil?
      ::NullChainer.new(::Null::Object.instance)
    else
      super
    end
  end
end

Instance Method Details

#getObject



6
7
8
# File 'lib/nullobject_chain.rb', line 6

def get
  @obj
end