Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

memoized values, like rspec's let

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.markdown

Let

Memoized methods for objects, like rspec's let.

class Foo
  include Let
  let(:field1) { rand }
end

foo = Foo.new
foo.field1 # =>
foo.instance_variable_get("@field1") == foo.field1

Rails

Let is automatically included into ActiveRecord and ActionController

So for example, if you are using AuthLogic, and you have a method in your ApplicationController that looks like this:

def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end

You can rewrite that as:

let(:current_user_session) { UserSession.find }

Copyright

Copyright (c) 2010 Howard Yeh. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.