Dynamically Define Methods

Posted by root Fri, 11 Jan 2008 07:21:00 GMT

Perl
package MyClass;
package main;

*MyClass::from_my_class = sub { 
   print "defined in ", __PACKAGE__, "\n" 
};

MyClass::from_my_class();
Ruby
class String
  def self.from_string
    print "defined in " + self.name + $/
  end
end

String::from_string
String. from_string

Posted in ,  | Tags ,  | no comments

Comments

Comments are disabled