in reply to on the fly methods
This is Perl, not Ruby. Methods are subs in a given package, not properties of individual instances. You possibly could do some dark magic with AUTOLOAD (make it lookup say $self->{_instancemethods}->{$AUTOLOAD} and call that if it exists), or eval new code into the instance's package (eval qq{ package @{[ ref $self ]}; sub { "NEW CODE" }}; however that's going to make the method available on all instances of that class (and its descendants) not just the one in $self)).
Perhaps you could elaborate on what you're trying to do and you might get better suggestions (e.g. yes, you're trying to emulate Ruby's
in order to add a method on a single instance).class << obj def new_method "fweeee" end end
Update: Formatting and wording tweaks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: on the fly methods
by diotalevi (Canon) on Feb 27, 2007 at 16:44 UTC | |
by stvn (Monsignor) on Feb 27, 2007 at 21:49 UTC | |
by friedo (Prior) on Feb 27, 2007 at 16:48 UTC | |
by jettero (Monsignor) on Feb 27, 2007 at 16:55 UTC | |
by diotalevi (Canon) on Feb 27, 2007 at 18:47 UTC | |
by blazar (Canon) on Feb 28, 2007 at 12:45 UTC |