Aliasing a singleton method of a Class object

Discussion in 'Ruby' started by Yuri Leikind, Sep 10, 2004.

  1. Yuri Leikind

    Yuri Leikind Guest

    Hello all,

    Aliasing an object method is simple:


    class QQQ
    def aaa
    end

    alias_method:)new_name_for_aaa, :aaa)
    end


    How do I alias a singleton method of a Class object (or, as many call it, a class method) ?


    class QQQ
    def self.aaa
    end
    end


    --
    Best regards,
    Yuri Leikind
     
    Yuri Leikind, Sep 10, 2004
    #1
    1. Advertising

  2. Yuri Leikind

    ts Guest

    >>>>> "Y" == Yuri Leikind <> writes:

    Y> class QQQ
    Y> def self.aaa
    Y> end
    Y> end

    class QQQ
    class << self
    def aaa
    end

    alias new_name_for_aaa aaa
    end
    end


    Guy Decoux
     
    ts, Sep 10, 2004
    #2
    1. Advertising

  3. Hi --

    On Fri, 10 Sep 2004, Yuri Leikind wrote:

    > Hello all,
    >
    > Aliasing an object method is simple:
    >
    >
    > class QQQ
    > def aaa
    > end
    >
    > alias_method:)new_name_for_aaa, :aaa)
    > end
    >
    >
    > How do I alias a singleton method of a Class object (or, as many call it, a class method) ?
    >
    >
    > class QQQ
    > def self.aaa
    > end
    > end


    You have to get into the class where the singleton method is defined
    -- namely, the singleton class of the object QQQ:

    class << QQQ
    alias_method:)new_name_for_aaa, :aaa)
    end


    David

    --
    David A. Black
     
    David A. Black, Sep 10, 2004
    #3
  4. Yuri Leikind

    Yuri Leikind Guest

    On Fri, 10 Sep 2004 19:29:03 +0900
    "David A. Black" <> wrote:


    >
    > You have to get into the class where the singleton method is defined
    > -- namely, the singleton class of the object QQQ:
    >
    > class << QQQ
    > alias_method:)new_name_for_aaa, :aaa)
    > end


    Ah yes, thank you!



    --
    Best regards,
    Yuri Leikind
     
    Yuri Leikind, Sep 10, 2004
    #4
  5. Yuri Leikind

    Cai Li Guest

    A simple NARRAY question

    Hi,

    Problem:How can I put data into a NArray object

    my code looks like this:

    VALUE x0;
    x0 = na_make_object(5,2,array_shape,cNArray);/* array_shape is an array
    containing {n,1} */
    GetNArray(x0,na_x0);
    for (i = 1; i <= array_shape[0]; i++)
    na_x0->ptr[i - 1] = 1.0;
    ....

    Here,I have specified all the elements in na_x0 into 1.0,
    then how to put the latest value into x0?

    I checked almost all the methods in narray.c,but it seems that they can
    only
    create emply NArray objects or copy from other objects.
     
    Cai Li, Sep 10, 2004
    #5
  6. Re: A simple NARRAY question

    Hi,

    > Problem:How can I put data into a NArray object
    >
    > my code looks like this:
    >
    > VALUE x0;
    > x0 = na_make_object(5,2,array_shape,cNArray);/* array_shape is an array
    > containing {n,1} */
    > GetNArray(x0,na_x0);
    > for (i = 1; i <= array_shape[0]; i++)
    > na_x0->ptr[i - 1] = 1.0;


    Here should be;

    *(double*)(na_x0->ptr[i - 1]) = 1.0;

    > Here,I have specified all the elements in na_x0 into 1.0,
    > then how to put the latest value into x0?


    No such backport process is needed.

    Masahiro Tanaka
     
    Masahiro TANAKA, Sep 12, 2004
    #6
  7. Yuri Leikind

    Cai Li Guest

    Re: A simple NARRAY question

    Thank you,it's just what i need


    Cai Li
    ----- Original Message -----
    From: "Masahiro TANAKA" <>
    To: "ruby-talk ML" <>; <>
    Sent: Sunday, September 12, 2004 1:50 PM
    Subject: Re: A simple NARRAY question


    > Hi,
    >
    > > Problem:How can I put data into a NArray object
    > >
    > > my code looks like this:
    > >
    > > VALUE x0;
    > > x0 = na_make_object(5,2,array_shape,cNArray);/* array_shape is an array
    > > containing {n,1} */
    > > GetNArray(x0,na_x0);
    > > for (i = 1; i <= array_shape[0]; i++)
    > > na_x0->ptr[i - 1] = 1.0;

    >
    > Here should be;
    >
    > *(double*)(na_x0->ptr[i - 1]) = 1.0;
    >
    > > Here,I have specified all the elements in na_x0 into 1.0,
    > > then how to put the latest value into x0?

    >
    > No such backport process is needed.
    >
    > Masahiro Tanaka
     
    Cai Li, Sep 12, 2004
    #7
  8. Yuri Leikind

    Cai Li Guest

    Re: A simple NARRAY question

    but your code will raise a segmentation fault.

    >*(double*)(na_x0->ptr[i - 1]) = 1.0;


    then i modified it ,and this one should work:

    double *x0_ptr;
    x0_ptr = (double *)na_x0->ptr;
    for (...)
    x0_ptr[i-1] = 1.0;





    Cai Li wrote:

    >Thank you,it's just what i need
    >
    >
    >Cai Li
    >----- Original Message -----
    >From: "Masahiro TANAKA" <>
    >To: "ruby-talk ML" <>; <>
    >Sent: Sunday, September 12, 2004 1:50 PM
    >Subject: Re: A simple NARRAY question
    >
    >a
    >
    >
    >>Hi,
    >>
    >>
    >>
    >>>Problem:How can I put data into a NArray object
    >>>
    >>>my code looks like this:
    >>>
    >>>VALUE x0;
    >>>x0 = na_make_object(5,2,array_shape,cNArray);/* array_shape is an array
    >>>containing {n,1} */
    >>>GetNArray(x0,na_x0);
    >>>for (i = 1; i <= array_shape[0]; i++)
    >>> na_x0->ptr[i - 1] = 1.0;
    >>>
    >>>

    >>Here should be;
    >>
    >> *(double*)(na_x0->ptr[i - 1]) = 1.0;
    >>
    >>
    >>
    >>>Here,I have specified all the elements in na_x0 into 1.0,
    >>>then how to put the latest value into x0?
    >>>
    >>>

    >>No such backport process is needed.
    >>
    >>Masahiro Tanaka
    >>
    >>
     
    Cai Li, Sep 12, 2004
    #8
    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. Jeffrey E. Forcier
    Replies:
    7
    Views:
    329
    Christopher Subich
    Jul 24, 2005
  2. Jeffrey E. Forcier
    Replies:
    2
    Views:
    333
    Jeffrey E. Forcier
    Jul 24, 2005
  3. Francis Hwang
    Replies:
    4
    Views:
    140
    Pit Capitain
    Mar 8, 2005
  4. Paul McMahon
    Replies:
    3
    Views:
    224
    David A. Black
    Jun 9, 2008
  5. Charles Oliver Nutter

    Singleton methods without the singleton class

    Charles Oliver Nutter, Mar 15, 2010, in forum: Ruby
    Replies:
    4
    Views:
    222
    Charles Oliver Nutter
    Mar 22, 2010
Loading...

Share This Page