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.
a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama
Hey dude, the name OpenObject is straight from Facets. And except for
your special attribute DSL, is similar in function.
http://facets.rubyforge.org/rdoc/OpenObjects/index.html
Not a major issue, of course, but certainly can't hurt to avoid name
conflicts. Care to change the name?
T.
>
> Not a major issue, of course, but certainly can't hurt to avoid name
> conflicts. Care to change the name?
>
> T.
suggestions?
> Merge the two projects! ;)
they are actually quite a bit different - otherwise not a bad idea.
in particular mine is geared toward open behaviour (methods) not only
properties. still - might be possible...
Aren't they both namespaced? If so, where's the collison?
Later,
--
Bil Kleb
http://fun3d.larc.nasa.gov
> Aren't they both namespaced? If so, where's the collison?
who is this 'namespaced' you speak of?
;-)
LOL. cool :) downloading now...
thanks for openobject.. nice name too.
kind regards -botp
> For that matter, there are at least two others?
>
> % gem search openobject
>
> *** LOCAL GEMS ***
>
> *** REMOTE GEMS ***
> Need to update 27 gems from http://gems.rubyforge.org
> ...........................
> complete
>
> calibre-openobject (1.0.0)
> OpenObject is an improved variation of OpenStruct
>
> openobject (1.3.0)
> OpenObject is an improved variation of OpenStruct
>
In retrospect I'm surprised there aren't more.
> Steve
>
>
>
Brainstorming! Sorry, I have to add #comments :)
How about this:
FreeStruct # hehe
BetterStruct # yay! good indication!
protoobject # original yeah? :D
proteusobject # for a change, why only proto, why not proteus...
libreobject # i dont like that one, but who cares!
objectfate # this object starts blank, but it will grow slowly to
accept its fate in the world!
PS: I think a small problem with facets is that it looks big and
intimidating (to me, I have installed facets but didnt really
dig into it). Such smaller projects as this one are nice to have!
--
Posted via http://www.ruby-forum.com/.
On Sep 11, 5:15 pm, Steven Lumos <ste...@lumos.us> wrote:
> For that matter, there are at least two others?
>
> % gem search openobject
>
> *** LOCAL GEMS ***
>
> *** REMOTE GEMS ***
> Need to update 27 gems fromhttp://gems.rubyforge.org
> ...........................
> complete
>
> calibre-openobject (1.0.0)
> OpenObject is an improved variation of OpenStruct
>
> openobject (1.3.0)
> OpenObject is an improved variation of OpenStruct
calibre-openobject is an older version of openobject. All the calibre-
* gems will be deleted soon actually, as that library was was merged
into Facets a while ago. The openobject gem is a stand-alone release
of the Facets library. I've long debated if I should release parts of
Facets in small individual packages. I've tested the waters in that
regard with a few libraries like this one. If there's enough demand, I
may continue to do so, but in the mean time my focus has been on
tightening up the the single package.
T.
On Sep 9, 12:52 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Sep 9, 2007, at 1:38 PM, Logan Capaldo wrote:
>
> > Merge the two projects! ;)
>
> they are actually quite a bit different - otherwise not a bad idea.
> in particular mine is geared toward open behaviour (methods) not only
> properties. still - might be possible...
I don't see a great deal of difference between Ara's openobject and
just using his attribute library with OpenStruct (perhaps with an
extra extension or two). OTOH, Facets' OpenObject class is designed to
be better than OpenStruct in some ways. It's faster, more open, and
doesn't have issues with #dup and so forth b/c of the use of singleton
methods.
On the surface however, the main item of difference is really the
#attribute method. Certainly Facets could incorporate that
functionality, but it sort of goes against the grain of it's
annotations system, which allows any piece of information to be
attached to attributes, not just default values. For example, Ara's
lib does:
attribute :x => 10
Where Facets' would do:
attr_accessor :x, :default => 10
At the moment Facets' annotations library doesn't do anything with the
annotations. So this is just a syntax distinction, not a functional
one. But I've always planned to expand the annotations system to
handle this, and a few other features like casting. It is for this
reason alone that I have never incorporated Ara's, otherwise excellent
attribute language.
Eventually I will get the annotations system handling it. The trick
has been finding a good way to generalize the procedure so others can
easily add there own "functional significance" to annotations. The key
to this may lie in around advice, actually. We shall see.
T.