Ruby - define_method, method_missing, and instance_eval
By Jiazhen Xie | 2 November 2013
Tags: ruby, metaprogramming, advanced
Ruby's define_method, method_missing, and instance_eval are always mysterious to new starter. I put effort to understand what exactly they are. Here are the notes of what I've got. Define_method lets you create methods using a method rather than the language builtin . One major benefit of this is that you can reduce the duplication inherent methods with similar definitions. For example, the following methods all pull data out of an internal hash: With , we can iterate over each method name and r...
← Back to Home