How to understand the difference between class_eval() and instance_eval()?
As the documentation says, class_eval evaluates the string or block in the context of the Module or Class. So the following pieces of code are equivalent: class String def lowercase self.downcase end end String.class_eval do def lowercase self.downcase end end In each case, the String class has been reopened and a new method defined. That … Read more