Broken alias behavior in Ruby 1.9.2?

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 :old_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

On Aug 29, 5:25 pm, Tron Fu [email protected] wrote:

alias :old_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 :old_encode64 :encode64
end
end

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 S. wrote:

On Aug 29, 5:25�pm, Tron Fu [email protected] wrote:

� alias :old_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 :old_encode64 :encode64
end
end

Thanks, Michael.

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

Tron

Michael M. 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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs