Class#aliases?

Discussion in 'Ruby' started by Giles Bowkett, Oct 11, 2007.

  1. Giles Bowkett, Oct 11, 2007
    #1
    1. Advertising

  2. 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.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
    --
    Posted via http://www.ruby-forum.com/.
    Wolfgang Nádasi-Donner, Oct 11, 2007
    #2
    1. Advertising

  3. Giles Bowkett

    Konrad Meyer Guest

    --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 <> 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--
    Konrad Meyer, Oct 11, 2007
    #3
  4. 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.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


    --
    Posted via http://www.ruby-forum.com/.
    Wolfgang Nádasi-Donner, Oct 11, 2007
    #4
  5. 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-forum.com/.
    Wolfgang Nádasi-Donner, Oct 11, 2007
    #5
  6. Giles Bowkett

    Trans Guest

    On Oct 10, 9:58 pm, "Giles Bowkett" <> 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.
    Trans, Oct 11, 2007
    #6
  7. On Oct 11, 2:46 am, "Wolfgang N=E1dasi-Donner" <>
    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.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 =3D String
    > Hugo =3D String
    > p String.aliases? # =3D> ["Hugo", "String", "Otto"]
    >
    > Wolfgang N=E1dasi-Donner
    >
    > --
    > Posted viahttp://www.ruby-forum.com/.


    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
    Yossef Mendelssohn, Oct 11, 2007
    #7
  8. > 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.blogspot.com
    Portfolio: http://www.gilesgoatboy.org
    Tumblelog: http://giles.tumblr.com/
    Giles Bowkett, Oct 11, 2007
    #8
  9. Trans wrote:
    >
    > On Oct 10, 9:58 pm, "Giles Bowkett" <> 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-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
    Daniel Berger, Oct 18, 2007
    #9
    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. Roedy Green

    enum aliases

    Roedy Green, Jun 26, 2005, in forum: Java
    Replies:
    5
    Views:
    3,830
    Roedy Green
    Jun 30, 2005
  2. Kevin
    Replies:
    5
    Views:
    2,152
    Jack Klein
    Feb 6, 2004
  3. Michael Surette

    superuser access to aliases database file

    Michael Surette, Nov 26, 2003, in forum: Python
    Replies:
    0
    Views:
    281
    Michael Surette
    Nov 26, 2003
  4. mp
    Replies:
    24
    Views:
    801
    Floyd L. Davidson
    May 3, 2006
  5. Martin Douglas

    Website Reference Aliases Not Exposed?

    Martin Douglas, Jan 4, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    306
    Martin Douglas
    Feb 13, 2007
Loading...

Share This Page