Aliasing a singleton method of a Class object

Y

Yuri Leikind

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
 
T

ts

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
 
D

David A. Black

Hi --

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
 
Y

Yuri Leikind

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

Cai Li

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

Masahiro TANAKA

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
 
C

Cai Li

Thank you,it's just what i need


Cai Li
----- Original Message -----
From: "Masahiro TANAKA" <[email protected]>
To: "ruby-talk ML" <[email protected]>; <[email protected]>
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
 
C

Cai Li

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 said:
Thank you,it's just what i need


Cai Li
----- Original Message -----
From: "Masahiro TANAKA" <[email protected]>
To: "ruby-talk ML" <[email protected]>; <[email protected]>
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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top