Aliasing operators possible?

Discussion in 'Ruby' started by GGarramuno, Dec 31, 2003.

  1. GGarramuno

    GGarramuno Guest

    I'd like to alias the =~ operator, is this possible?

    This is what I'm doing and what I get:

    Normal aliasing of a method (all fine):

    irb(main):015:0> class String
    irb(main):016:1> alias :eek:ldsub :sub
    irb(main):017:1> def sub(a,b)
    irb(main):018:2> p "sub"
    irb(main):019:2> oldsub(a,b)
    irb(main):020:2> end
    irb(main):021:1> end

    irb(main):027:0>"abc".sub(/a/,"")
    "sub"
    => "bc"

    ------------------------------------------

    Aliasing of =~ (not fine)

    irb(main):001:0> class String
    irb(main):002:1> alias :eek:ld=~ :=~
    irb(main):003:1> def =~(pat)
    irb(main):004:2> p "new"
    irb(main):005:2> old=~(pat)
    irb(main):006:2> end
    irb(main):007:1> end

    SyntaxError: compile error
    (irb):2: syntax error
    alias :eek:ld=~ :=~
    ^
    GGarramuno, Dec 31, 2003
    #1
    1. Advertising

  2. GGarramuno

    Tim Hunter Guest

    On Wed, 31 Dec 2003 15:48:42 -0800, GGarramuno wrote:

    > SyntaxError: compile error
    > (irb):2: syntax error
    > alias :eek:ld=~ :=~
    > ^


    "old=~" isn't a legal method name. Try

    alias :eek:ld_match :=~
    Tim Hunter, Jan 1, 2004
    #2
    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. Tim Tyler

    LCD anti-aliasing in Java

    Tim Tyler, Sep 4, 2003, in forum: Java
    Replies:
    2
    Views:
    1,269
    Tim Tyler
    Sep 5, 2003
  2. Kevin Bertman

    Anti-aliasing GIF Images

    Kevin Bertman, Nov 26, 2004, in forum: Java
    Replies:
    4
    Views:
    720
    marcus
    Nov 29, 2004
  3. Replies:
    25
    Views:
    675
    Steve Holden
    May 18, 2006
  4. Aspidus
    Replies:
    3
    Views:
    263
    Aspidus
    Apr 29, 2007
  5. Crom
    Replies:
    13
    Views:
    149
    Ilya Zakharevich
    Dec 17, 2004
Loading...

Share This Page