Sha256: 46d0dd9689f7ff9a723a85678821680c76b23552a40906f7d47449f1651cdbe0

Contents?: true

Size: 507 Bytes

Versions: 1

Compression:

Stored size: 507 Bytes

Contents

# frozen_string_literal: true

module BasicTemperature
  class Temperature
    module Memoization
      private

      def memoized(key)
        name = convert_to_variable_name(key)

        instance_variable_get(name) if instance_variable_defined?(name)
      end

      def memoize(key, proc)
        name = convert_to_variable_name(key)
        value = proc.call

        instance_variable_set(name, value)
      end

      def convert_to_variable_name(key)
        "@#{key}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basic_temperature-1.0.0 lib/basic_temperature/temperature/memoization.rb