[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Class#aliases?

Giles Bowkett

10/11/2007 4:59:00 AM

Does this method exist? I think that it doesn't, but I just thought
I'd make sure.

--
Giles Bowkett

Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles.t...

8 Answers

Wolfgang Nádasi-donner

10/11/2007 5:37:00 AM

0

Giles Bowkett wrote:
> Does this method exist? I think that it doesn't, but I just thought
> I'd make sure.
>
> --
> Giles Bowkett
>
> Blog: http://gilesbowkett.bl...
> Portfolio: http://www.gilesg...
> Tumblelog: http://giles.t...

It is not necessary, because Classe are objects...

irb(main):001:0> class Otto
irb(main):002:1> def hi
irb(main):003:2> puts "Hi!"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> Hugo = Otto
=> Otto
irb(main):007:0> Otto.new.hi
Hi!
=> nil
irb(main):008:0> Hugo.new.hi
Hi!
=> nil

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

Konrad Meyer

10/11/2007 5:39:00 AM

0

Quoth Giles Bowkett:
> Does this method exist? I think that it doesn't, but I just thought
> I'd make sure.
>
> --
> Giles Bowkett
>
> Blog: http://gilesbowkett.bl...
> Portfolio: http://www.gilesg...
> Tumblelog: http://giles.t...

Irb says no, but I'd guess you'd have already tried that.

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

Wolfgang Nádasi-donner

10/11/2007 7:46:00 AM

0

Giles Bowkett wrote:
> Does this method exist? I think that it doesn't, but I just thought
> I'd make sure.
>
> --
> Giles Bowkett
>
> Blog: http://gilesbowkett.bl...
> Portfolio: http://www.gilesg...
> Tumblelog: http://giles.t...

Again - it cannot exist. The syntactic element "alias" cannot be applied
to local variables, instance variables, class variables and constants -
because class names are (usually) constants, they can't have aliases. If
you use normal assignment to constants for aliasing classes a simple
method can be defined...

class Class
def aliases?
Module.constants.find_all{|c|self.equal?(const_get(c))}
end
end

Otto = String
Hugo = String
p String.aliases? # => ["Hugo", "String", "Otto"]

Wolfgang Nádasi-Donner


--
Posted via http://www.ruby-....

Wolfgang Nádasi-donner

10/11/2007 10:13:00 AM

0

Wolfgang Nádasi-Donner wrote:
> Giles Bowkett wrote:
>> ...

btw - is there a difference between "alias" and "alias_method" if
applied to a method name (I don't mean that I must use Symbols in
"alias_method)?

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

Trans

10/11/2007 2:28:00 PM

0



On Oct 10, 9:58 pm, "Giles Bowkett" <gil...@gmail.com> wrote:
> Does this method exist? I think that it doesn't, but I just thought
> I'd make sure.

Do you mean that you'd like a list of all aliases defined in a class,
similar to #instance_methods?

T.


Yossef Mendelssohn

10/11/2007 2:31:00 PM

0

On Oct 11, 2:46 am, "Wolfgang Nádasi-Donner" <ed.oda...@wonado.de>
wrote:
> Giles Bowkett wrote:
> > Does this method exist? I think that it doesn't, but I just thought
> > I'd make sure.
>
> > --
> > Giles Bowkett
>
> > Blog:http://gilesbowkett.bl...
> > Portfolio:http://www.gilesg...
> > Tumblelog:http://giles.t...
>
> Again - it cannot exist. The syntactic element "alias" cannot be applied
> to local variables, instance variables, class variables and constants -
> because class names are (usually) constants, they can't have aliases. If
> you use normal assignment to constants for aliasing classes a simple
> method can be defined...
>
> class Class
> def aliases?
> Module.constants.find_all{|c|self.equal?(const_get(c))}
> end
> end
>
> Otto = String
> Hugo = String
> p String.aliases? # => ["Hugo", "String", "Otto"]
>
> Wolfgang Nádasi-Donner
>
> --
> Posted viahttp://www.ruby-....

It seems you and I understood the question in two different ways. Only
Giles can answer this for certain, but I don't think you're answering
the question he asked.

I understood the point of Class#aliases to mean not "Are there any
other constants out there that are really the same class object, and
if so, what are they?" but "Are there any methods in this class that
are aliases for other methods, and if so, what are the connections?"

Giles, please explain.

--
-yossef


Giles Bowkett

10/11/2007 7:22:00 PM

0

> Giles, please explain.
>
> --
> -yossef

I was skimming, and read that as "Giles, please explain yourself."

Anyway -

> Do you mean that you'd like a list of all aliases defined in a class,
> similar to #instance_methods?

Actually no. I was looking at an error message that expected #aliases
to exist, and I thought it was weird.

> I understood the point of Class#aliases to mean not "Are there any
> other constants out there that are really the same class object, and
> if so, what are they?" but "Are there any methods in this class that
> are aliases for other methods, and if so, what are the connections?"

Nope, it was just a weird error message referencing some internal
code. But both these interpretations are pretty interesting.

Technically, as I learned from Ryan Davis, you **can** actually
"alias" a class, even though you can't **alias** a class.

>> Monkey = String
=> String
>> m = Monkey.new("asdf")
=> "asdf"
>> m.gsub!(/asdf/, "qwerty")
=> "qwerty"

--
Giles Bowkett

Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles.t...

Daniel Berger

10/18/2007 11:21:00 AM

0

Trans wrote:
>
> On Oct 10, 9:58 pm, "Giles Bowkett" <gil...@gmail.com> wrote:
>> Does this method exist? I think that it doesn't, but I just thought
>> I'd make sure.
>
> Do you mean that you'd like a list of all aliases defined in a class,
> similar to #instance_methods?

If so, I brought this up a while back:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

Ryan Davis came up with a rather interesting solution. :)

One problem right off the bat, however, is that the Ruby source would
need to be modified to be more stringent about using true aliases in
order such a method to be accurate.

Regards,

Dan