From: Holden Glova Date: 2002-05-05T08:30:31+09:00 Subject: Re: dynamically assigning instance variables -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 04 May 2002 23:56, ts wrote: > >>>>> "H" == Holden Glova writes: > > H> instance_eval(<<-EOS) > [...] > H> send("#{name}=", v) > > eval is evil, and it's still exist a stupid way to write it :-) > > pigeon% cat b.rb > #!/usr/bin/ruby > module Hab > module Tmp > def defin(a) > attr_accessor a > end > end > > def self.append_features(c) > super > c.extend Tmp > end > > def biv(attributes) > attributes.each do |k, v| > type.send(:defin, k) > send(k.to_s + "=", v) > end > end > > end > > class A > include Hab > end > > a = A.new > a.biv("aaa" => [1, 2], :bbb => [3, 4]) > p a.aaa > p a.bbb > pigeon% > > pigeon% b.rb > [1, 2] > [3, 4] > pigeon% > > > Guy Decoux I definately have a long way to go with Ruby - solutions like this do not come naturally to me and only make sense after much examination. *drifts off into a dream job of useing Ruby*. Thanks for the tip. - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE81G5N+mF116Lw2cQRAhBoAJ9uqAkq4GcvJvUV6ozrYwtyFdlvwQCgjD0B Q+l7R/Y9kEVfrkf7CS4WOzE= =lEFw -----END PGP SIGNATURE-----