1. Make a library file(suppose "your_extension.rb") into your project's lib folder
2. require File.join(RAILS_ROOT,'lib/your_extension.rb')
- Add the above line at the End of environment.rb file
3.Suppose you want to extend Ruby Fixnum Class with your mehtods(named prime?) then PASTE the following code into "your_extension.rb"
n = self
counter = 0
if(n%i == 0)
counter += 1
if(counter == 2)
4. Restart your Rails application and you are done!
5. Now you can call prime? method from anywhere of your Rails application like
2.prime? -- returns true
5.prime? -- returns true
10.prime? -- returns false