I wish to make a custom method (e.g. def plus_two(x) x + 2 end
and have it be accessible everywhere within the app - that is, accessible in the controller, model, console, views, tests, and any other .rb
files. I currently have the same method defined in many areas of the app, and wish to make it DRY
How can this be achieved?
Note: I don't mind if calling the method requires prepending something (I have seen some answers where methods are prepended with ::
or with a namespace, but otherwise have a preference to keep code succinct where possible
I have done some reading at similar questions (e.g. this one) but I can't quite get it