From: Meador Inge Date: 2006-02-20T02:08:33+09:00 Subject: Re: [/QUIZ] metakoans.rb (#67) This is definitely a great quiz. I had a ton of fun working and and learned a great deal about Ruby as well. I am relatively a Nuby. Anyway, here is what I came up with: class Module def attribute(*objects, &block) objects.each { |object| attr = object.is_a?(Hash) ? object : {object => nil} symbol = attr.keys[0] default = block || lambda { attr[symbol] } define_method("#{symbol}?") { instance_eval &default } class_eval "alias #{symbol} #{symbol}?" define_method("#{symbol}=") { |value| instance_eval %{ def #{symbol}?; @#{symbol}; end alias #{symbol} #{symbol}? @#{symbol} = value } } } end end