method_missing

Discussion in 'Ruby' started by Simon Corcoran, Sep 29, 2010.

  1. [Note: parts of this message were removed to make it a legal post.]

    Hi, I have extended BDI::Row as below in order to use dot notation to
    retrieve columns values from result rows. It seems however that some methods
    like inspect for example now get caught as missing by this hook and are not
    found and executed as expected. Could anyone shed any light on this
    behaviour please?

    class DBI::Row
    def method_missing(name, *args)
    puts "method missing #{name}"
    result = by_field(name)
    end
    end

    simon
    Simon Corcoran, Sep 29, 2010
    #1
    1. Advertising

  2. On Wed, Sep 29, 2010 at 1:22 PM, Simon Corcoran <> wrote:
    > Hi, I have extended BDI::Row as below in order to use dot notation to
    > retrieve columns values from result rows. It seems however that some methods
    > like inspect for example now get caught as missing by this hook and are not
    > found and executed as expected. Could anyone shed any light on this
    > behaviour please?
    >
    > class DBI::Row
    > def method_missing(name, *args)
    > puts "method missing #{name}"
    > result = by_field(name)
    > end
    > end
    >
    > simon
    >


    Are you talking about Ruby/DBI?

    http://ruby-dbi.rubyforge.org/git?p...40396ee59c6cf36ab9fec937f38f012570e4d;hb=HEAD

    DBI::Row uses DelegateClass to delegate some of the behaviour to an
    Array. Right now I'm not really sure how DelegateClass works
    underneath, but it seems your overriding of method_missing is messing
    with it.

    Sorry, I don't have a solution right now.

    Jesus.
    Jesús Gabriel y Galán, Sep 29, 2010
    #2
    1. Advertising

  3. ahh interesting - i'll look into that, thanks - my first attempt
    at meta-programming so still a lot to learn

    2010/9/29 Jes=FAs Gabriel y Gal=E1n <>

    > On Wed, Sep 29, 2010 at 1:22 PM, Simon Corcoran <> wrote:
    > > Hi, I have extended BDI::Row as below in order to use dot notation to
    > > retrieve columns values from result rows. It seems however that some

    > methods
    > > like inspect for example now get caught as missing by this hook and are

    > not
    > > found and executed as expected. Could anyone shed any light on this
    > > behaviour please?
    > >
    > > class DBI::Row
    > > def method_missing(name, *args)
    > > puts "method missing #{name}"
    > > result =3D by_field(name)
    > > end
    > > end
    > >
    > > simon
    > >

    >
    > Are you talking about Ruby/DBI?
    >
    >
    > http://ruby-dbi.rubyforge.org/git?p=3Druby-dbi.git;a=3Dblob;f=3Dlib/dbi/r=

    ow.rb;h=3Ddcf40396ee59c6cf36ab9fec937f38f012570e4d;hb=3DHEAD
    >
    > DBI::Row uses DelegateClass to delegate some of the behaviour to an
    > Array. Right now I'm not really sure how DelegateClass works
    > underneath, but it seems your overriding of method_missing is messing
    > with it.
    >
    > Sorry, I don't have a solution right now.
    >
    > Jesus.
    >
    >
    Simon Corcoran, Sep 29, 2010
    #3
  4. Thanks Jes=FAs, the following seems to work

    class DBI::Row
    def method_missing(name, *args, &block)
    return __getobj__.send(name, *args, &block) if __getobj__.respond_to?(name)
    result =3D by_field(name)
    end
    end


    On Wed, Sep 29, 2010 at 12:38 PM, Simon Corcoran <> wrote:

    > ahh interesting - i'll look into that, thanks - my first attempt
    > at meta-programming so still a lot to learn
    >
    > 2010/9/29 Jes=FAs Gabriel y Gal=E1n <>
    >
    > > On Wed, Sep 29, 2010 at 1:22 PM, Simon Corcoran <>

    > wrote:
    > > > Hi, I have extended BDI::Row as below in order to use dot notation to
    > > > retrieve columns values from result rows. It seems however that some

    > > methods
    > > > like inspect for example now get caught as missing by this hook and a=

    re
    > > not
    > > > found and executed as expected. Could anyone shed any light on this
    > > > behaviour please?
    > > >
    > > > class DBI::Row
    > > > def method_missing(name, *args)
    > > > puts "method missing #{name}"
    > > > result =3D by_field(name)
    > > > end
    > > > end
    > > >
    > > > simon
    > > >

    > >
    > > Are you talking about Ruby/DBI?
    > >
    > >
    > >

    > http://ruby-dbi.rubyforge.org/git?p=3Druby-dbi.git;a=3Dblob;f=3Dlib/dbi/r=

    ow.rb;h=3Ddcf40396ee59c6cf36ab9fec937f38f012570e4d;hb=3DHEAD
    > >
    > > DBI::Row uses DelegateClass to delegate some of the behaviour to an
    > > Array. Right now I'm not really sure how DelegateClass works
    > > underneath, but it seems your overriding of method_missing is messing
    > > with it.
    > >
    > > Sorry, I don't have a solution right now.
    > >
    > > Jesus.
    > >
    > >

    >
    Simon Corcoran, Sep 29, 2010
    #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. mrstevegross

    An idea for method_missing

    mrstevegross, Apr 29, 2009, in forum: Python
    Replies:
    1
    Views:
    351
    Gabriel Genellina
    Apr 30, 2009
  2. Xiangrong Fang

    How to use "method_missing"?

    Xiangrong Fang, Jun 6, 2004, in forum: Ruby
    Replies:
    3
    Views:
    104
    George Ogata
    Jun 7, 2004
  3. Neil Mc Laughlin

    method_missing and send

    Neil Mc Laughlin, Jun 14, 2004, in forum: Ruby
    Replies:
    7
    Views:
    146
    Paul Brannan
    Jun 16, 2004
  4. zuzu
    Replies:
    0
    Views:
    97
  5. Replies:
    0
    Views:
    224
Loading...

Share This Page