i had a simple idea.
first, think about:
p = proc{|x| x*2}
we can call the proc with ‘[]’:
p[3] # => 6
there’s another way, which caches the result:
p = Hash.new{|h, x| h[x] = x*2}
we have the same interface as a proc call:
p[3] # => 6
then, a little bit more:
class Proc
def memoise
Hash.new {|h,k| h[k] = self[k]}
end
end
finally defining a cached ‘proc’ is clearer:
p = proc{|x| x*2}.memoise
So, with the benifits of the above things, how about switching rails
helper methods from defs to procs ? then you can define cached or
uncached helpers easily, and you can even use a hash or anything (which
responds to []) as a helper.
maybe route helpers can be a little bit faster ?