Module: Sinclair::MethodDefinition::BlockHelper Private
- Defined in:
- lib/sinclair/method_definition/block_helper.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helper for wrapping block with cacheing
Class Method Summary collapse
-
.cached_method_proc(method_name, &inner_block) ⇒ Proc
private
Returns proc block when #cached? as simple.
-
.full_cached_method_proc(method_name, &inner_block) ⇒ Proc
private
Returns proc block when #cached? as full.
Class Method Details
.cached_method_proc(method_name, &inner_block) ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns proc block when Sinclair::MethodDefinition#cached? as simple
17 18 19 20 21 22 23 24 25 |
# File 'lib/sinclair/method_definition/block_helper.rb', line 17 def cached_method_proc(method_name, &inner_block) proc do instance_variable_get("@#{method_name}") || instance_variable_set( "@#{method_name}", instance_eval(&inner_block) ) end end |
.full_cached_method_proc(method_name, &inner_block) ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns proc block when Sinclair::MethodDefinition#cached? as full
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sinclair/method_definition/block_helper.rb', line 32 def full_cached_method_proc(method_name, &inner_block) proc do if instance_variable_defined?("@#{method_name}") instance_variable_get("@#{method_name}") else instance_variable_set( "@#{method_name}", instance_eval(&inner_block) ) end end end |