Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

lazy_attr_reader and lazy_attr_accessor convenience methods. Similar to lazy_reader, found in the grit library

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION.yml
Octocat-spinner-32 lazy_attr.gemspec
README.markdown

LazyAttr

Extend your class with LazyAttr:

require "rubygems"
require "lazy_attr"

class MyClass
  extend LazyAttr

  lazy_attr_reader :foo, lambda { 17 }
  attr_writer :foo

  lazy_attr_accessor :bar, lambda { Time.now }
end

Use it like a typical attr_reader or attr_accessor:

>> obj = MyClass.new
=> #<MyClass:0x260818>

>> obj.foo
=> 17
>> obj.foo = 18
=> 18
>> obj.foo
=> 18

>> obj.bar
=> Mon Feb 23 01:41:15 -0500 2009
>> obj.bar
=> Mon Feb 23 01:41:15 -0500 2009
>> obj.bar = Time.now
=> Mon Feb 23 01:41:20 -0500 2009
>> obj.bar
=> Mon Feb 23 01:41:20 -0500 2009

Scott Taylor // scott@railsnewbie.com

Something went wrong with that request. Please try again.