From: "Jan E." Date: 2012-04-11T12:25:02+09:00 Subject: Re: A Beginner's Question about Metaprogramming Phil Stone wrote in post #1055945: > Whoa, so my code is outdated? Yes. The example code was obviously written for Ruby 1.8. While it still works in 1.9, many of the boilerplate parts aren't needed any longer. > How would [def self.metaclass; class << self; self; end; end] be > rewritten using this syntax? You can skip this part completely and use "define_singleton_method" instead of "define_method": #### def self.traits( *arr ) return @traits if arr.empty? # 1. Set up accessors for each variable attr_accessor *arr # 2. Add a new class method to for each trait. arr.each do |a| define_singleton_method( a ) do |val| @traits ||= {} @traits[a] = val end end end ### -- Posted via http://www.ruby-forum.com/.