Module: T::CompatibilityPatches::RSpecCompatibility::MemoizedHelpers
- Defined in:
- lib/types/compatibility_patches.rb
Instance Method Summary collapse
-
#let(name, &block) ⇒ Object
let!,subject, andsubject!are implemented by dispatching tolet, so this should cover those methods too.
Instance Method Details
#let(name, &block) ⇒ Object
let!, subject, and subject! are implemented by dispatching to
let, so this should cover those methods too.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/types/compatibility_patches.rb', line 62 def let(name, &block) res = T::Private::DeclState.current.without_on_method_added do # Allow the `let`-defined methods to be defined super end return res unless T::Private::DeclState.current.active_declaration # Force the `sig` to attach to the outer `let`-defined method, # not the one inside the `LetDefinitions` module. Re-running # `define_method` with the method we grab via reflection there # triggers the `method_added`, which allows the active_declaration # to be consumed. # # Unfortunately, this means that the runtime checks are not # memoized (but they never were). # # (An alternative approach of pretending that the `sig` was actually # written inside the `LetDefinitions` module didn't work, because # things like `sig {override}` broke: the `LetDefinitions` module # has no ancestors and thus does not override anything) method = instance_method(name) remove_method(name) define_method(name, method) res end |