# Broken alias behavior in Ruby 1.9.2?

**URL:** <https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075>\
**Category:** Ruby\
**Created:** [August 29, 2010, 11:25pm UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075 "2010-08-29T23:25:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@tron](https://www.ruby-forum.com/u/tron)\
**Post date:** [August 29, 2010, 11:25pm UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075/1 "2010-08-29T23:25:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@tron](https://www.ruby-forum.com/u/tron)\
**Post date:** [August 30, 2010, 12:15am UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075/2 "2010-08-30T00:15:32Z")

</div>

On Aug 29, 5:25 pm, Tron Fu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![tron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@tron](https://www.ruby-forum.com/u/tron)\
**Post date:** [August 30, 2010, 2:04am UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075/3 "2010-08-30T02:04:21Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![tron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@tron](https://www.ruby-forum.com/u/tron)\
**Post date:** [August 30, 2010, 4:33pm UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075/4 "2010-08-30T16:33:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@tron](https://www.ruby-forum.com/u/tron)\
**Post date:** [August 30, 2010, 2:51am UTC](https://www.ruby-forum.com/t/broken-alias-behavior-in-ruby-1-9-2/194075/5 "2010-08-30T02:51:51Z")

</div>

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.
