Lazy evaluation in Ruby

Posted by fifigyuri on Stack Overflow See other posts from Stack Overflow or by fifigyuri
Published on 2010-03-17T10:26:36Z Indexed on 2010/03/17 10:31 UTC
Read the original article Hit count: 337

Filed under:
|

I have a situation for Ruby, where an object is possibly necessary to be created, but it is not sure. And as the creation of the object might be costly I am not too eager creating it. I think this is a clear case for lazy loading. How can I define an object which is not created only when someone sends a message to it? The object would be created in a block. Is there a way for simple lazy loading/initialisation in Ruby? Are these things supported by some gems, which provide different solutions for various cases of lazy initialisation of objects? Thanks for your suggestions!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about lazy-loading