Sha256: af636eedb0639b982961f64af5209a822bd10b3f093859317f525530ac4fae68

Contents?: true

Size: 1.06 KB

Versions: 31

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

class Sinclair
  class MethodDefinition
    # @api private
    # @author darthjee
    #
    # Helper for wrapping block with cacheing
    module BlockHelper
      module_function

      # @private
      #
      # Returns proc block when {#cached?} as simple
      #
      # @return [Proc]
      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

      # @private
      #
      # Returns proc block when {#cached?} as full
      #
      # @return [Proc]
      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
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/method_definition/block_helper.rb
sinclair-2.1.0 lib/sinclair/method_definition/block_helper.rb
sinclair-2.0.1 lib/sinclair/method_definition/block_helper.rb
sinclair-2.0.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.16.3 lib/sinclair/method_definition/block_helper.rb
sinclair-1.16.2 lib/sinclair/method_definition/block_helper.rb
sinclair-1.16.1 lib/sinclair/method_definition/block_helper.rb
sinclair-1.16.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.15.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.14.2 lib/sinclair/method_definition/block_helper.rb
sinclair-1.14.1 lib/sinclair/method_definition/block_helper.rb
sinclair-1.14.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.13.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.12.1 lib/sinclair/method_definition/block_helper.rb
sinclair-1.12.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.11.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.10.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.9.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.8.0 lib/sinclair/method_definition/block_helper.rb
sinclair-1.7.0 lib/sinclair/method_definition/block_helper.rb