Re: Anonymous classes?
by 7stud -- other posts by this author
Oct 21 2007 1:02AM messages near this date
Anonymous classes?
|
Re: Anonymous classes?
Ben Tilly wrote:
> Here is what I'd like to do.
>
> anonymous_class = class.new;
>
> # somehow define methods on anonymous_class
>
> # somehow create an object of type anonymous_class
>
How about something like this:
Dog = Class.new {
def self.create_method(name, proc_)
self.send(:define_method, name, proc_)
end
}
p = lambda {puts "Woof, woof."}
Dog.create_method(:bark, p)
d = Dog.new
d.bark
--
Posted via http://www.ruby-forum.com/.
Thread:
Ben Tilly
7stud --
Ben Tilly
Jimmy Kofler
Ben Tilly
Sebastian Hungerecker
Ezra Zygmuntowicz
Ben Tilly
|