Michael Ulm
2/21/2006 7:43:00 AM
Awesome quiz! Here is my solution, quite ugly I'm afraid.
Meta_value = {}
def attribute(name, &block)
(name.is_a?(Hash) ? name : {name => nil}).each do |key, value|
define_method(key.to_sym) do
if Meta_value[[self, key]].nil?
Meta_value[[self, key]] = (block_given? ? instance_eval(&block) : value)
else
Meta_value[[self, key]]
end
end
define_method((key + "=").to_sym) {|val| Meta_value[[self, key]] = val}
define_method((key + "?").to_sym) {not Meta_value[[self, key]].nil?}
end
end
--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-219, fax: +43 2236 21081
e-mail: michael.ulm@isis-papyrus.com
Visit our Website: www.isis-papyrus.com
---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------