Metaprogramming in ruby is great because I constantly use it to emulate prototype based programming and quickly write prototype solutions to some problems to test their viability. So I would like to know if there is any essential difference between the following pieces of code:
(class << some_object; self; end).class_eval do
define_method(:method_name) do ... method body ... end
end
and
(class << some_object; self; end).instance_eval do
define_method(:method_name) do ... method body ... end
end
Both versions of the code define a singleton method and I haven't yet come up against anything that has forced me to choose the (instance_eval, define_method)
combination over the (class_eval, define_method)
combination to define a singleton method and I'm wondering if there is some essential difference between the two.