[REXML] why not Element#[] ?

G

gabriele renzi

Hi gurus and nubys,

I was just wondering why access to attributes of an element is done
just via #attributes#[].
IMO it would be nice to have Element#[] like:

def [](k)
attributes[k]
end

and ditto for #[]=

Anyway, Sean Russel is my personal XML deity so if this is not allowed
there may be a reason: what is this reason?
 
S

Sean Russell

gabriele renzi said:
I was just wondering why access to attributes of an element is done
just via #attributes#[].

Element#[] is already defined, since it is inherited from Parent. #[]
references all child nodes of an element except attributes.
if this is not allowed there may be a reason: what is this reason?

It was, primarily, a design decision: either Element#[] references
nodal children, or Element#[] references attributes. I chose the
children.

--- SER
 
G

gabriele renzi

il 26 Jul 2004 09:06:38 -0700, (e-mail address removed) (Sean Russell)
ha scritto::
gabriele renzi said:
I was just wondering why access to attributes of an element is done
just via #attributes#[].

Element#[] is already defined, since it is inherited from Parent. #[]
references all child nodes of an element except attributes.

oops, sorry I just took a look at the quick RDoc api and did not
thought of inheritance
if this is not allowed there may be a reason: what is this reason?

It was, primarily, a design decision: either Element#[] references
nodal children, or Element#[] references attributes. I chose the
children.

well, sure now this makes sense, thanks a lot :)
 
S

Sean Russell

gabriele renzi said:
Element#[] is already defined, since it is inherited from Parent. #[]
references all child nodes of an element except attributes.

oops, sorry I just took a look at the quick RDoc api and did not
thought of inheritance

No problem. The fact that rdoc doesn't include inherited methods in
the class signature bites everyone, sooner or later, including me.


--- SER
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top