From: 7stud -- Date: 2009-09-06T02:09:30+09:00 Subject: Re: something.new( :attribute => value) thing Marc-antoine Kruzik wrote: > # Do I have to create attributes ? > attr_accessor :opts > attr_accessor :x > attr_accessor :y > > def initialize(application, title, ??? ) > > @application = application > @title = title > > ??? > > end > > > end > class A def initialize(arg1, arg2, hash) hash.each do |key, val| A.send(:attr_accessor, key) send("#{key}=", val) end end end a = A.new("hello", "world", :x => 10, :y => 20, :z => "red") puts a.x puts a.y puts a.z --output:-- 10 20 red a.x = "hello" a.y = "goodbye" a.z = "the end" puts a.x puts a.y puts a.z --output:-- hello goodbye the end -- Posted via http://www.ruby-forum.com/.