Here is my solution: I got stuck on like 6, so I borrowed a line and
a half from Adam S…
I understand it looks a lot like his code, but I swear, i only
borrowed 12 and part of 13 from him!
#!/usr/local/bin/ruby
Created by me on 2007-10-05.
Some code (lines 12, and part of 13) borrowed from Adam S.
Copyright © 2007. All pwnage reserved.
class Object
def attribute(*vars, &b)
vars.each do |var|
var.each_pair{|k,v| attribute [k,v] } and next if var.is_a? Hash
var, v = var # Idea borrowed [stolen] from Adam S…
Brilliant, I might add!
class_eval “def #{var}; @#{var} = (defined?(@#{var}) ? @#
{var} : #{var}_proc); end” # Set up getters
attr_writer var.to_sym #
setters
class_eval “def #{var}?; return (self.#{var}.nil? ? false :
true ); end” # and queries
define_method “#{var}_proc”, b || Proc.new {v}
end
end
end
Ari B.
--------------------------------------------|
If you’re not living on the edge,
then you’re just wasting space.