Skip to content

hayeah/let

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

memoized values, like rspec's let

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages