From: Eli Bendersky Date: 2006-05-07T00:19:07+09:00 Subject: Creating sub-classes using Struct Hello, There are two Ruby features I want to combine. One is sub-classes (or embedded classes): class Foo def initialize(x) puts "new Foo #{x}" end class Bar def initialize(y) puts "new Bar #{y}" end end end joe = Foo::Bar.new(12) # prints "new Bar 12" Another is dynamic creation of new classes using Struct: Customer = Struct.new(:name, :address) #=> Customer eddy = Customer.new("Dave", "123 Main") Here 'Customer' is a class and 'eddy' is an instance of the Customer class. Now, by combining the features, I mean creating a subclass of Foo dynamically, using Struct. The following pseudo-code demonstates it (pseudo because it obviously doesn't work and only shows what I'm trying to do): class Foo def initialize(x) puts "new Foo #{x}" end Bar = Struct.new(:name, :address) end eddy = Foo::Bar.new("Dave", "123 Main") How can this be done ? TIA Eli -- Posted via http://www.ruby-forum.com/.