Where is the best place to add methods to the Integer class in Rails?

前端 未结 7 2194
死守一世寂寞
死守一世寂寞 2021-02-10 05:56

Where is the best place to add a method to the integer class in Rails? I\'d like to add a to_meters and to_miles methods.

相关标签:
7条回答
  • 2021-02-10 06:58

    I agree monkey patching should be used with care, but occasionally it just make sense. I really like the helpers that allow you to type 5.days.ago which are part of the active_support library

    So some of the other answers might be better in this case, but if you are extending ruby classes we keep all our extensions in lib/extensions/class_name.rb

    this way when working on a project it is quick and easy to find and see anything that might be out of the ordinary with standard classes.

    0 讨论(0)
提交回复
热议问题