[REXML] why not Element#[] ?

Discussion in 'Ruby' started by gabriele renzi, Jul 23, 2004.

  1. 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?
     
    gabriele renzi, Jul 23, 2004
    #1
    1. Advertising

  2. gabriele renzi

    Sean Russell Guest

    gabriele renzi <> wrote in message news:<>...
    > 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
     
    Sean Russell, Jul 26, 2004
    #2
    1. Advertising

  3. il 26 Jul 2004 09:06:38 -0700, (Sean Russell)
    ha scritto::

    >gabriele renzi <> wrote in message news:<>...
    >> 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 :)
     
    gabriele renzi, Jul 27, 2004
    #3
  4. gabriele renzi

    Sean Russell Guest

    gabriele renzi <> wrote in message news:<>...
    > >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
     
    Sean Russell, Jul 27, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    922
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,076
    Smokey Grindel
    Dec 2, 2006
  3. Damphyr
    Replies:
    2
    Views:
    148
    Damphyr
    Jul 16, 2003
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    157
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    149
    Phlip
    Jan 15, 2008
Loading...

Share This Page