From: Phil Stone Date: 2012-04-17T06:54:28+09:00 Subject: Re: A Beginner's Question about Metaprogramming Thanks for all the help, but there are some more question that I have: 1. Why is it necessary to use a Singleton class in the above example at all? Here's the code where it is used: arr.each do |a| metaclass.instance_eval do define_method( a ) do |val| @traits ||= {} @traits[a] = val end end end (I know this code is outdated, I'm just trying to understand the concepts.) Why are the methods defined onto the Singleton class? I would rather think that the following is correct, but for some reason it doesn't work: arr.each do |a| class_eval do define_method( a ) ... For what the code is supposed to do, this seems like the right function... but it does not work. Why? Why was a metaclass necessary? 2.. I still don't grasp exactly what class << self means. I know that class << ClassName would add on to the class of ClassName. Please explain. Thanks. Lastly, for anybody else who is struggling with Ruby metaprogramming, I found this article to be very useful: http://rubysource.com/ruby-metaprogramming-part-i/ -- Posted via http://www.ruby-forum.com/.