Class: Chef::Decorator::LazyArray

Inherits:
Lazy show all
Defined in:
lib/chef/decorator/lazy_array.rb

Overview

Lazy Array around Lazy Objects

This makes access lazy through #[]. In order to implement #each we need to know how many items we have and what their indexes are, so we'd have to evaluate the proc which makes that impossible. You can call methods like #each and the decorator will forward the method, but item access will not be lazy.

at() and #fetch() are not implemented but technically could be.

outputs:

started
still lazy
allocated
value

Examples:

def foo
    puts "allocated"
      "value"
end

a = Chef::Decorator::LazyArray.new { [ foo ] }

puts "started"
a[0]
puts "still lazy"
puts a[0]

Since:

  • 12.10.x

Instance Method Summary collapse

Methods inherited from Lazy

#__getobj__, #initialize

Methods inherited from Chef::Decorator

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

Constructor Details

This class inherits a constructor from Chef::Decorator::Lazy

Dynamic Method Handling

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

Instance Method Details

#[](idx) ⇒ Object

Since:

  • 12.10.x



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

def [](idx)
  block = @block
  Lazy.new { block.call[idx] }
end