Looking for some help with extending existing classes. In a view I have <td><%=h bmevent.node %></td>. I need further processing on the output and added a helper: module ApplicationHelper class String def a self[ /^[^\0]*/ ] end end end and <td><%=h bmevent.node.a %></td> 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 <td><%=b bmevent.node.a %></td> 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 ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 26 Jan 2009, at 22:25, X wrote:> > Looking for some help with extending existing classes. > > In a view I have <td><%=h bmevent.node %></td>. I need further > processing on the output and added a helper: > > module ApplicationHelper > class String > def a > self[ /^[^\0]*/ ] > end > end > endThat 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> Any ideas ? > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Case closed. Thanx. a lot. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---