Meinrad Recheis
3/7/2006 9:43:00 AM
On 3/7/06, Meinrad Recheis <meinrad.recheis@gmail.com> wrote:
>
> hello fellow rubyists,
>
> is there an elegant way to define a singleton method from a given symbol
> without using eval? what i am doing is this:
>
> def make_wrapper object, method
> eval %{
> def object.#{method}
> # do something here
> super # call the wrapped method
> end
> }
> end
sorry the above code does not work, (needs to be done using
object.instance_eval) but you get the idea what i mean
# example of usage:
> make_wrapper STDOUT, :puts
>
> using eval works, but it seems not to be the best solution. is there
> annother way do define methods from a given symbol?
>
> -- henon
>
>