Sha256: ed71d3c13b5c547ebc89b01915f6a9d77c5abd1129a8e2402d3cd3978cff0c08

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

module Pry::Config::Memoization
  MEMOIZED_METHODS = Hash.new {|h,k| h[k] = [] }

  module ClassMethods
    #
    # Defines one or more methods who return a constant value after being
    # called once.
    #
    # @example
    #   class Foo
    #     include Pry::Config::Memoization
    #     def_memoized({
    #       foo: proc {1+10},
    #       bar: proc{"aaa"<<"a"}
    #     })
    #   end
    #
    # @param [{String => Proc}] method_table
    #
    # @return [void]
    #
    def def_memoized(method_table)
      method_table.each do |method_name, method|
        define_method(method_name) do
          method_table[method_name] = instance_eval(&method) if method_table[method_name].equal? method
          method_table[method_name]
        end
      end
      MEMOIZED_METHODS[self] |= method_table.keys
    end
  end

  def self.included(mod)
    mod.extend(ClassMethods)
  end

  #
  # @return [Array<Symbol>]
  #   Returns the names of methods that have been defined by {ClassMethods#def_memoized}.
  #
  def memoized_methods
    MEMOIZED_METHODS[self.class]
  end
end

Version data entries

20 entries across 20 versions & 8 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/config/memoization.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/config/memoization.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/config/memoization.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/config/memoization.rb
pry-0.11.3 lib/pry/config/memoization.rb
pry-0.11.3-java lib/pry/config/memoization.rb
pry-0.11.2 lib/pry/config/memoization.rb
pry-0.11.2-java lib/pry/config/memoization.rb
tdiary-5.0.6 vendor/bundle/gems/pry-0.11.0/lib/pry/config/memoization.rb
pry-0.11.1 lib/pry/config/memoization.rb
pry-0.11.1-java lib/pry/config/memoization.rb
pry-0.11.0 lib/pry/config/memoization.rb
pry-0.11.0-java lib/pry/config/memoization.rb