ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Anonymous classes?
by Ben Tilly other posts by this author
Oct 20 2007 10:29PM messages near this date
Float::MIN Not an actual minimum? | Re: Anonymous classes?
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

And I'm running into a roadblock.  I can create an anonymous class
easily enough, I just can't figure out how to define methods on it.
Like initialize.  Or create objects of that type.

Yes, I know about singleton classes, but they don't do what I want
because I also want to create subclasses of these subclasses, and
instances of these subclasses.

As for why I want this, I'm trying to see whether I can figure out how
to implement a decent prototype based class system in Ruby.  A friend
says that you can't.  I thought that a clean way to do it would be to
create an anonymous class, and create an object Prototype of that class.
I would make sure that Prototype's new method would create a new class
which is a subclass of Prototype's, and an object of that class with the
prototype being the object that new was called on.  And Prototype would
have a def method which would define new methods in the class of the
object that def was called on.

And yes, I know I could do this by dynamically creating normal classes
with calls to eval.  But I'd prefer to avoid going there.

Thanks,
Ben
-- 
Posted via http://www.ruby-forum.com/.
Thread:
Ben Tilly
7stud --
Ben Tilly
Jimmy Kofler
Ben Tilly
Sebastian Hungerecker
Ezra Zygmuntowicz
Ben Tilly

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved