Get Version


→ ‘lazyeval’


This gem provides a very simple lazy evaluation for Ruby


sudo gem install lazyeval

The basics

This GEM allows to call methods lazily. i.e. the actual work will not be performed until the result is used. There’s no promise/force semantics. just a single call (or block) is stored and executed the first time the (lazy) result is accessed.

Demonstration of usage

  1. simple lazy call user = User.lazy.find(:first) # will not access a db puts # this will actually perform the find and then get the name from # the result
  1. example for a lazy block user_name = User.lazy { |user| user.find(:first).user_name } # no db access puts user_name # db will be accessed here

How to submit patches

Clone the repository on git://


This code is free to use under the terms of the MIT license.


Comments are welcome. Send an email to “vitaly at astrails dot com”

Vitaly Kushner, 24th April 2008
Theme extended from Paul Battley