From: Florian Gross Date: 2004-09-29T05:24:21+09:00 Subject: Re: metaprogramming question, alternatives to "class ..." Kevin McConnell wrote: > In other words, say I have something like this: > > class AddressDataSource < DataSourceBase > field :name, "customer_name" > field :address, "cust_addr" > end > > ...is there any cunning trickery that would allow me to do this: > > datasource AddressDataSource > field :name, "customer_name" > field :address, "cust_addr" > end You can have this: datasource(:AddressDataSource) do field :name, "customer_name" field :address, "cust_addr" end With this: def datasource(name, &block) Object.const_set(name, Class.new(DataSourceBase, &block)) end > Cheers, > Kevin Regards, Florian Gross