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 ?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---