From: "Jesús Gabriel y Galán" Date: 2010-02-12T19:27:32+09:00 Subject: Re: String to symbol On Fri, Feb 12, 2010 at 11:12 AM, Sergey Sheypak wrote: > >> I referred to passing strings to #initialize.  This certainly works. >> But the more dramatic issue persists (see above). > Seems like I got it here: > http://www.ruby-forum.com/topic/204068 > > Is there any opportunity to add attributes to instance, not to class? Send the define method to the singleton class of the object, instead of sending it to the class: irb(main):001:0> class Task irb(main):002:1> def initialize options irb(main):003:2> options.each_pair do |k,v| irb(main):004:3* (class << self; self; end).send(:define_method, k, Proc.new{v}) irb(main):005:3> end irb(main):006:2> end irb(main):007:1> end => nil irb(main):008:0> t = Task.new(:id => 1) => # irb(main):009:0> t.id => 1 irb(main):010:0> t2 = Task.new(:id => 2) => # irb(main):012:0> t.id => 1 irb(main):013:0> t2.id => 2 Jesus.