Topic: adding methods to pre defined classes

If I want to add some methods to an existing class, where should I put the class definitions?

For exemple:

class Integer
    def odd?
        return self % 2 == 1
    end
end

I tried creating an integer.rb file, but rails won't use it.
Thanks

Re: adding methods to pre defined classes

Place that integer.rb file (you may want to name it something more specific) into the "lib" directory in your rails project. Then you need to require it in your config/environment.rb file:

require 'integer'

Then restart the web server and it should load it.

Railscasts - Free Ruby on Rails Screencasts

Re: adding methods to pre defined classes

thanks, I had put the integer.rb in the model folder... yikes
and sorry for asking stupid questions

Re: adding methods to pre defined classes

Nah, don't be sorry. You asked a good question.

Railscasts - Free Ruby on Rails Screencasts

Re: adding methods to pre defined classes

One teacher I had always said: "There are no stupid questions, just stupid answers!"

I always keep this in my mind. (There has to be something what I've learned in school :-)

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/