Hey guys this should be an easy one,
how do i define a method that i can reuse for strings.
eg/ “mystring”.sanitize
i know how to write the regex for such a method but where would i put
it ???
cheers Adam
Hey guys this should be an easy one,
how do i define a method that i can reuse for strings.
eg/ “mystring”.sanitize
i know how to write the regex for such a method but where would i put
it ???
cheers Adam
On 4/02/2008, at 11:01 PM, Adam J. wrote:
i think i may have answered it …
String.class_eval do
# define new method
def sanitize
self.gsub(/[^[:alnum:]]+/, ‘_’)
end
end
i dumed that into my app controller and its working
class String
def sanitize
self.gsub(/[^[:alnum:]]+/, ‘_’)
end
end
end
Is better looking
On Feb 4, 2008 8:33 PM, Adam J. [email protected] wrote:
i know how to write the regex for such a method but where would i put
# define new method
def sanitize
self.gsub(/[^[:alnum:]]+/, ‘_’)
end
endi dumed that into my app controller and its working
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
On 4/02/2008, at 11:35 PM, Ryan B. wrote:
put
# define new method–
Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
Thanks.
Where is the ideal place to put that??
I have a file in my lib called custom_methods.rb, I load it by doing
require
‘custom_methods’ in my environment file, I put all my class additions in
there.
On Feb 4, 2008 9:09 PM, Adam J. [email protected] wrote:
Is better looking
i think i may have answered it …
Thanks.
Where is the ideal place to put that??
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs