Sha256: 8de77cbeecfeb6bc04f3e4522fb1e007ae63332ac6e770a3aeed28a50303bb56

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

class Pry
  class Config < Pry::BasicObject
    module 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
  end
end

Version data entries

15 entries across 15 versions & 7 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
chess_engine-0.0.2 vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb
chess_engine-0.0.1 vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/config/memoization.rb
pry-0.12.2-java lib/pry/config/memoization.rb
pry-0.12.2 lib/pry/config/memoization.rb
pry-0.12.1 lib/pry/config/memoization.rb
pry-0.12.1-java lib/pry/config/memoization.rb
pry-0.12.0 lib/pry/config/memoization.rb
pry-0.12.0-java lib/pry/config/memoization.rb