module RSpec::Core::MemoizedHelpers::ClassMethods
def let(name, &block)
- Note: - Because `let` is designed to create state that is reset between
Note: - `let` can be configured to be threadsafe or not.
Note: - `let` _can_ enhance readability when used sparingly (1,2, or
def let(name, &block) # We have to pass the block directly to `define_method` to # allow it to use method constructs like `super` and `return`. raise "#let or #subject called without a block" if block.nil? raise( "#let or #subject called with a reserved name #initialize" ) if :initialize == name MemoizedHelpers.module_for(self).__send__(:define_method, name, &block) # Apply the memoization. The method has been defined in an ancestor # module so we can use `super` here to get the value. if block.arity == 1 define_method(name) { __memoized.fetch_or_store(name) { super(RSpec.current_example, &nil) } } else define_method(name) { __memoized.fetch_or_store(name) { super(&nil) } } end end