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