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
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

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