--0015175888847ba56e048e7f8a3a
Content-Type: text/plain; charset=UTF-8

Yikes. There's rarely a good reason to need to call eval. And the rest of
this seems really awkward, too. I would recommend watching Dave Thomas'
metaprogramming screencast, where he solves the metaprogramming problem
(literally) 9 different ways, and talks about the pros and cons. It's at
http://pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogrammingand
you can either get just episode 5, or get the whole screencast, it's
well worth the money.

On Mon, Aug 23, 2010 at 11:18 AM, Intransition <transfire / gmail.com> wrote:

> Like to get some thoughts on the following technique for memoization:
>
>  # Memoize a method.
>  #
>  #   class MemoExample
>  #     attr_accessor :a
>  #     def m
>  #       memo{ @a }
>  #     end
>  #   end
>  #
>  #   ex  emoExample.new
>  #
>  #   ex.a  0
>  #   ex.m  #10
>  #
>  #   ex.a  0
>  #   ex.m  #10
>  #
>  def memo(&block)
>    key  val('__method__', block)
>    val  lock.call
>    singleton_class  class << self; self; end)
>    singleton_class.__send__(:define_method, key){ val }
>    val
>  end
>
> Downside / upsides to the approach? Any suggestions for improvement?
> Or is this just an altogether bad idea?
>
>

--0015175888847ba56e048e7f8a3a--