memoized values, like rspec's let
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
Gemfile
LICENSE.txt
README.markdown
Rakefile
VERSION
let.gemspec

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.