Monkey Patching in Rails 3

后端 未结 2 935
时光取名叫无心
时光取名叫无心 2020-11-27 16:47

What is the preferred way to Monkey Patch in Rails 3?

I just want to add a method to the String class. I\'m more looking at where to place the file.

2条回答
  •  旧巷少年郎
    2020-11-27 17:12

    If it is class specific you could just re-define the method in the class you need it for. Otherwise, it totally depends on which part of the app you want to use your string method. As an example of opening a class to redefine a method: http://codepad.org/Cj1LHmQj but, you probably already knew you could do that.

提交回复
热议问题