Broken alias behavior in Ruby 1.9.2?

Discussion in 'Ruby' started by Tron Fu, Aug 29, 2010.

  1. Tron Fu

    Tron Fu Guest

    The following code works in Ruby 1.8.7 but not in 1.9.2, instead, I get
    the error:
    NoMethodError: undefined method `old_encode64' for Base64:Module

    Can someone please shed some light on this.

    Thanks in advance,
    Tron

    module Base64
    alias :eek:ld_encode64 :encode64
    module_function # this seems to be necessary -- get a "wrong number of
    arguments (2 for 1)" without it this line.

    def encode64(bin,options={})
    if (options[:no_line_break] == true)
    old_encode64(bin).gsub(/\n/, '')
    else
    old_encode64(bin)
    end
    end
    end
    --
    Posted via http://www.ruby-forum.com/.
    Tron Fu, Aug 29, 2010
    #1
    1. Advertising

  2. Tron Fu

    Intransition Guest

    On Aug 29, 5:25=A0pm, Tron Fu <> wrote:
    > The following code works in Ruby 1.8.7 but not in 1.9.2, instead, I get
    > the error:
    > NoMethodError: undefined method `old_encode64' for Base64:Module
    >
    > Can someone please shed some light on this.
    >
    > Thanks in advance,
    > Tron
    >
    > module Base64
    > =A0 alias :eek:ld_encode64 :encode64
    > =A0 module_function # this seems to be necessary -- get a "wrong number o=

    f
    > arguments (2 for 1)" without it this line.
    >
    > =A0 def encode64(bin,options=3D{})
    > =A0 =A0 if (options[:no_line_break] =3D=3D true)
    > =A0 =A0 =A0 old_encode64(bin).gsub(/\n/, '')
    > =A0 =A0 else
    > =A0 =A0 =A0 old_encode64(bin)
    > =A0 =A0 end
    > =A0 end
    > end


    Your alias is only creating an instance method, yet you are using it
    as a class method.

    To be sure I would need to look at the original code, but presumely

    module Base64
    class << self
    =A0 alias :eek:ld_encode64 :encode64
    end
    end
    Intransition, Aug 29, 2010
    #2
    1. Advertising

  3. Tron Fu

    Tron Fu Guest

    Thank you for your reply. However, your suggestion resulted in
    SystemStackError: stack level too deep

    I'm guessing that it is not working in 1.9.2 because Base64 is no longer
    included with 1.9 and there is something odd going on with the
    ActiveSupport's version of it.

    Tron

    Thomas Sawyer wrote:
    > On Aug 29, 5:25�pm, Tron Fu <> wrote:
    >> � alias :eek:ld_encode64 :encode64
    >> end

    > Your alias is only creating an instance method, yet you are using it
    > as a class method.
    >
    > To be sure I would need to look at the original code, but presumely
    >
    > module Base64
    > class << self
    > � alias :eek:ld_encode64 :encode64
    > end
    > end


    --
    Posted via http://www.ruby-forum.com/.
    Tron Fu, Aug 30, 2010
    #3
  4. On 8/29/2010 8:04 PM, Tron Fu wrote:
    > Thank you for your reply. However, your suggestion resulted in
    > SystemStackError: stack level too deep
    >
    > I'm guessing that it is not working in 1.9.2 because Base64 is no longer
    > included with 1.9 and there is something odd going on with the
    > ActiveSupport's version of it.
    >
    > Tron


    As far as I can tell, 1.9.2 ships with Base64.

    I suspect you're having trouble because of Base64's use of
    module_function. This creates copies of the original methods, so it
    will be difficult to overload like this.

    --
    Michael Morin
    Guide to Ruby
    http://ruby.about.com/
    Become an About.com Guide: beaguide.about.com
    About.com is part of the New York Times Company
    Michael Morin, Aug 30, 2010
    #4
  5. Tron Fu

    Tron Fu Guest

    Thanks, Michael.

    I ended up not using and just reimplemented the base64 encode as
    [bin].pack("m")

    Tron

    Michael Morin wrote:
    > On 8/29/2010 8:04 PM, Tron Fu wrote:
    >> Thank you for your reply. However, your suggestion resulted in
    >> SystemStackError: stack level too deep
    >>
    >> I'm guessing that it is not working in 1.9.2 because Base64 is no longer
    >> included with 1.9 and there is something odd going on with the
    >> ActiveSupport's version of it.
    >>
    >> Tron

    >
    > As far as I can tell, 1.9.2 ships with Base64.
    >
    > I suspect you're having trouble because of Base64's use of
    > module_function. This creates copies of the original methods, so it
    > will be difficult to overload like this.


    --
    Posted via http://www.ruby-forum.com/.
    Tron Fu, Aug 30, 2010
    #5
    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. Twisted
    Replies:
    4
    Views:
    463
    Roedy Green
    Feb 23, 2006
  2. grocery_stocker
    Replies:
    9
    Views:
    755
    grocery_stocker
    May 24, 2008
  3. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    648
  4. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    584
    Cameron Simpson
    Sep 22, 2008
  5. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    603
    Fredrik Lundh
    Sep 22, 2008
Loading...

Share This Page