Class#aliases?

W

Wolfgang Nádasi-Donner

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

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/

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
 
K

Konrad Meyer

--nextPart1628914.bnSqn7YIhG
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Giles Bowkett:
Does this method exist? I think that it doesn't, but I just thought
I'd make sure.
=20
--=20
Giles Bowkett
=20
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/

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

=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart1628914.bnSqn7YIhG
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHDbcDCHB0oCiR2cwRAssOAKDGkNvVj1YyxNzvVBuLwvSYb0nZtwCgxmpc
Ri60U2UdXuy8eV4wUfWngrU=
=KhZ/
-----END PGP SIGNATURE-----

--nextPart1628914.bnSqn7YIhG--
 
W

Wolfgang Nádasi-Donner

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

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/

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
 
W

Wolfgang Nádasi-Donner

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
 
T

Trans

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

Yossef Mendelssohn

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

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 =3D String
Hugo =3D String
p String.aliases? # =3D> ["Hugo", "String", "Otto"]

Wolfgang N=E1dasi-Donner

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

Giles Bowkett

Giles, please explain.
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.
=> "qwerty"

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/
 
D

Daniel Berger

Trans said:
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-talk/196740

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
 

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

Similar Threads


Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top