3 ms·
No, no. Monkey patching is what you can do when you have open classes. For instance, in Ruby, I can reopen the Array class and add new behavior or change existe
by josevalim 16y ago
No, no. Monkey patching is what you can do when you have open classes. For instance, in Ruby, I can reopen the Array class and add new behavior or change existent methods. This is obviously bad idea if you are changing native behavior, but it is also what allows Ruby on Rails to extend the Integer class to make working with time expressions quite easy, as allowing the following expression: "3.days.ago".
I still haven't decided if Elixir will have open class or if I will add refinements or classboxes.
On other hand, module_eval is what allows frameworks like Rails to dynamically add code to a class, so you can do stuff like:
class Post
has_many :comments
end
And it will define a comments method and others, that allows you to easily manipulate the Post-Comment association.