0

I would like to add my_method to the Symbol class, and be able to call my_method from app/helpers/application_helper.rb:

module ApplicationHelper
  def my_helper
    my_symbol.my_method
  end
end

Where is the most appropriate place to put:

class Symbol
  def my_method
    <some code here>
  end
end

?

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • I asked a similar question that got a few more detailed answers here: http://stackoverflow.com/questions/3945124/how-can-i-use-mixins-or-modules-in-my-controllers-in-rails-3 – Jamison Dance Dec 13 '10 at 04:13

2 Answers2

2

I think that sticking your native class extensions in a new file in your lib folder and require-ing them in your environment.rb file should do it.

Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
0

I typically create a file named monkey_patches.rb (or similar) - so it's very obvious where the patches are - then load it with an initializer in config/initializers. That's what they're for!

Cory
  • 2,538
  • 2
  • 18
  • 19
  • Hi Cory! Where would you put the `monkey_patches.rb` file ? Do you mean to create a new file in `config/initializers` and put inside it `require 'monkey_patches'` ? – Misha Moroshko Dec 13 '10 at 04:07