lazy.rb

Path: lib/grit/lazy.rb
Last Update: Sat Dec 04 17:02:48 +0000 2010

Allows attributes to be declared as lazy, meaning that they won‘t be computed until they are asked for.

Works by delegating each lazy_reader to a cached lazy_source method.

class Person

  lazy_reader :eyes

  def lazy_source
    OpenStruct.new(:eyes => 2)
  end

end

>> Person.new.eyes

> 2

[Validate]