From: Daniel Finnie Date: 2008-05-08T01:03:06+09:00 Subject: Re: Reading from file, create a class with variables ------=_Part_2727_15227245.1210176185617 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I think that the Doodle Rubygem might be a good fit for this purpose, unless this is just an exercise to further your Ruby-fu. To make sure something is a string, you can use the kind_of? or is_a? methods. I would use kind_of? in this case (for the differences, check http://ruby-doc.org/core/classes/Object.html#M000371 ). Then, you just have to make sure things set with object.name = "ssdfd" are Strings using define_method: attr_name = :age attr_type = Fixnum klass.class_eval do define_method "#{attr_name}=" do |arg| self.instance_variable_set("@#{attr_name}", arg) if arg.type_of? attr_type end end And something similar for the initialize method. Dan On 5/7/08, Claes Rembrandt wrote: > > Pelle Strul wrote: > > Hi, I'm trying to load a file with specifications like: > > > > title :Person > > attribute :name, String > > attribute :age, Fixnum > > constraint :name, 'name != nil' > > constraint :name, 'name.size > 0' > > constraint :name, 'name =~ /^[A-Z]/' > > constraint :age, 'age >= 0' > > > Im also curious about how this could be solved... > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_2727_15227245.1210176185617--