[ANN] openobject-0.0.1

A

ara.t.howard

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

(e-mail address removed)


enjoy.


a @ http://drawohara.com/
 
T

Trans

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.

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.
 
L

Logan Capaldo

Aren't they both namespaced? If so, where's the collison?
I don't think google understands ruby namespaces, when I go searching
for "openobject" ;)
 
P

Peña, Botp

From: ara.t.howard [mailto:[email protected]]=20
# config =3D openobject do
# attribute :header =3D> openobject:)width =3D> 42, :height =
=3D> 42)
# attribute :body =3D> openobject:)width =3D> 4242, :height =
=3D> 4242)
# attribute :footer =3D> openobject:)width =3D> 42.0, :height =
=3D> 42.0)
# end
# p config.header.width
# p config.footer.height
# ~ > ruby sample/d.rb
# 42
# 42.0

LOL. cool :) downloading now...
thanks for openobject.. nice name too.
kind regards -botp
 
L

Logan Capaldo

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.
 
M

Marc Heiler

Care to change the name?

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!
 
T

Trans

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.
 
T

Trans

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top