Class: Grape::Util::LazyObject

Inherits:
BasicObject
Defined in:
lib/grape/util/lazy_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&callable) ⇒ LazyObject

Returns a new instance of LazyObject.



10
11
12
# File 'lib/grape/util/lazy_object.rb', line 10

def initialize(&callable)
  @callable = callable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



30
31
32
33
34
35
36
# File 'lib/grape/util/lazy_object.rb', line 30

def method_missing(method_name, *args, &block)
  if __target_object__.respond_to?(method_name)
    __target_object__.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#callableObject (readonly)

Returns the value of attribute callable.



8
9
10
# File 'lib/grape/util/lazy_object.rb', line 8

def callable
  @callable
end

Instance Method Details

#!Object



26
27
28
# File 'lib/grape/util/lazy_object.rb', line 26

def !
  !__target_object__
end

#!=(other) ⇒ Object



22
23
24
# File 'lib/grape/util/lazy_object.rb', line 22

def !=(other)
  __target_object__ != other
end

#==(other) ⇒ Object



18
19
20
# File 'lib/grape/util/lazy_object.rb', line 18

def ==(other)
  __target_object__ == other
end

#__target_object__Object



14
15
16
# File 'lib/grape/util/lazy_object.rb', line 14

def __target_object__
  @__target_object__ ||= callable.call
end

#respond_to_missing?(method_name, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/grape/util/lazy_object.rb', line 38

def respond_to_missing?(method_name, include_priv = false)
  __target_object__.respond_to?(method_name, include_priv)
end