lib/maglev/utils/memo.rb
# will update an existing method to be lazy evaluated
will update an existing method to be lazy evaluated
will update an existing method to be lazy evaluated
def memo(name)
        unbound = instance_method(name)
        if unbound.arity == 0
          define_method(name) do
            __memoized.fetch(name) { __memoized[name] = unbound.bind(self).call }
          end
        else
          define_method(name) do |*args|
            store = __memoized[name] ||= {}
            store.fetch(args) { store[args] = unbound.bind(self).call(*args) }
          end
        end
        name
      end
def memo ( name ) unbound = instance_method ( name ) if unbound . arity == 0 define_method ( name ) do __memoized . fetch ( name ) { __memoized [ name ] = unbound . bind ( self ) . call } end else define_method ( name ) do | * args | store = __memoized [ name ] ||= { } store . fetch ( args ) { store [ args ] = unbound . bind ( self ) . call ( * args ) } end end name end
will update an existing method to be lazy evaluated
will update an existing method to be lazy evaluated
# if the method takes no arguments then we do not need to cache based off of arguments, so use a faster lookup
name
<not_specific>