Class: Chef::Decorator::Lazy

Inherits:
Chef::Decorator show all
Defined in:
lib/chef/decorator/lazy.rb

Overview

Lazy wrapper to delay construction of an object until a method is called against the object.

outputs:

started
still lazy
allocated
value

Examples:


def foo
  puts "allocated"
  "value"
end

a = Chef::Decorator::Lazy.new { foo }

puts "started"
a
puts "still lazy"
puts a

Since:

  • 12.10.x

Direct Known Subclasses

LazyArray

Instance Method Summary collapse

Methods inherited from Chef::Decorator

#__setobj__, #is_a?, #kind_of?, #method_missing, #nil?

Constructor Details

#initialize(&block) ⇒ Lazy

Returns a new instance of Lazy.

Since:

  • 12.10.x



48
49
50
51
# File 'lib/chef/decorator/lazy.rb', line 48

def initialize(&block)
  super
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Decorator

Instance Method Details

#__getobj__Object

Since:

  • 12.10.x



53
54
55
56
# File 'lib/chef/decorator/lazy.rb', line 53

def __getobj__
  __setobj__(@block.call) unless defined?(@delegate_sd_obj)
  super
end