skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Top Posts

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

it's hailing in san franciscojessatianalyndaBird in the handkerimodeldanielle pettee and models-4449

Archives

Contact

Reach me at yan at pritzker.ws

Posted
4 September 2007 @ 8pm

Tagged
ruby

ruby tricks: simple caching of method results

This is a simple trick based on the idea that everything in ruby returns a result. By using the block syntax we can do a series of expensive operations and cache the result somewhere. Here I’ve shown the result cached in an instance variable but it may just as well be something more exotic.

  def caching_method
    @result || begin
      # expensive operation
      foo = expensive_operation_1
      @result = expensive_operation_2 * foo
    end
  end

No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

vi is in ur textmate Clean svn tag support for Capistrano 2