NAME
openobject
SYNOPSIS
a simple property based container that’s much more capable than a
blankslate
but far less polluted than ruby’s built-in OpenStruct. openobject
is a tiny
lib that couples the power of the ‘attributes’ gem alongside a
slightly
enhanced blankslate type object.
INSTALL
gem install openobject
URIS
http://codeforpeople.com/lib/ruby/
http://rubyforge.org/projects/codeforpeople/
SAMPLES
<========< sample/a.rb >========>
~ > cat sample/a.rb
require 'openobject'
oo = openobject
oo.foo = 42
oo.bar 'forty-two'
p oo.foo
p oo.bar
~ > ruby sample/a.rb
42
"forty-two"
<========< sample/b.rb >========>
~ > cat sample/b.rb
require 'openobject'
oo = openobject :foo => 42, :bar => 'forty-two' do
foobar 42.0
end
p oo.to_hash
p oo.attributes
~ > ruby sample/b.rb
{"foobar"=>42.0, "foo"=>42, "bar"=>"forty-two"}
["foo", "bar", "foobar"]
<========< sample/c.rb >========>
~ > cat sample/c.rb
require 'openobject'
oo = openobject :foo => 42
oo.bar = 'forty-two'
oo.extend do
attribute :foobar => 42.0
def barfoo
[ foo, bar, foobar ]
end
end
p oo.foobar
p oo.barfoo
~ > ruby sample/c.rb
42.0
[42, "forty-two", 42.0]
<========< sample/d.rb >========>
~ > cat sample/d.rb
require 'openobject'
config =
openobject do
attribute :header => openobject(:width => 42, :height => 42)
attribute :body => openobject(:width => 4242, :height => 4242)
attribute :footer => openobject(:width => 42.0, :height =>
42.0)
end
p config.header.width
p config.footer.height
~ > ruby sample/d.rb
42
42.0
AUTHOR
enjoy.