Skip to content

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

Notifications You must be signed in to change notification settings

smtlaissezfaire/lazy_attr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages