# Cannot extend class in Application Helper

**URL:** <https://www.ruby-forum.com/t/cannot-extend-class-in-application-helper/158699>\
**Category:** Rails\
**Created:** [January 26, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/cannot-extend-class-in-application-helper/158699 "2009-01-26T23:26:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cleca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@cleca](https://www.ruby-forum.com/u/cleca)\
**Post date:** [January 26, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/cannot-extend-class-in-application-helper/158699/1 "2009-01-26T23:26:47Z")

</div>

Looking for some help with extending existing classes.

In a view I have

\<%=h bmevent.node %\>. I need further  
processing on the output and added a helper:

module ApplicationHelper  
class String  
def a  
self[/^[^\0]\*/ ]  
end  
end  
end

and

\<%=h bmevent.node.a %\> results in an undefined method `a’  
for #String:0xb6c8105c error.

What am I doing wrong?

The helper is correctly found, since

module ApplicationHelper  
def b(text)  
text[/^[^\0]\*/ ]  
end  
end

and

\<%=b bmevent.node.a %\> produce the desired result, but  
this is (for other reasons) not what I want. I want to extend class  
string and use the postfix notation as in the first example.

Any ideas ?

---

<div class="post-metadata">

**Author:** ![cleca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@cleca](https://www.ruby-forum.com/u/cleca)\
**Post date:** [January 26, 2009, 11:33pm UTC](https://www.ruby-forum.com/t/cannot-extend-class-in-application-helper/158699/2 "2009-01-26T23:33:48Z")

</div>

On 26 Jan 2009, at 22:25, X wrote:

> end  
> end  
> end

That does not extend the String class. It defines a new class  
ApplicationHelper::String with an instance method a.  
I would have a method like that in a file somewhere in lib (eg lib/  
my\_extensions.rb) and require that from an initializer. You could  
‘fix’ it by pulling that out of the ApplicationHelper module and  
putting it at the bottom of the file but that’s a bit horrible.

Fred

---

<div class="post-metadata">

**Author:** ![cleca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@cleca](https://www.ruby-forum.com/u/cleca)\
**Post date:** [January 26, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/cannot-extend-class-in-application-helper/158699/3 "2009-01-26T23:47:54Z")

</div>

Case closed. Thanx. a lot.
