Class: Module

### Home Classes Methods

### In Files

- lib/tins/memoize.rb
- lib/tins/xt/annotate.rb
- lib/tins/xt/concern.rb
- lib/tins/xt/dslkit.rb
- lib/tins/xt/named.rb

### Parent

Object

### Methods

- #memoize_function
- #memoize_method
- #named

### Included Modules

- CacheMethods
- Tins::Annotate
- Tins::Concern::ModuleMixin
- Tins::Constant
- Tins::DSLAccessor
- Tins::ClassMethod
- Tins::Delegate
- Tins::ParameterizedModule
- Tins::FromModule
- Module

### Class/Module Index

Quicksearch

- Tins
- Tins
- Tins
- Tins::Annotate
- Tins::AskAndSend
- Tins::Attempt
- Tins::Bijection
- Tins::Blank
- Tins::Blank::Array
- Tins::Blank::FalseClass
- Tins::Blank::Hash
- Tins::Blank::NilClass
- Tins::Blank::Numeric
- Tins::Blank::Object
- Tins::Blank::String
- Tins::Blank::TrueClass
- Tins::BlankSlate
- Tins::BlockSelf
- Tins::CasePredicate
- Tins::ClassMethod
- Tins::Concern
- Tins::Concern::ModuleMixin
- Tins::Constant
- Tins::ConstantMaker
- Tins::CountBy
- Tins::DSLAccessor
- Tins::DateDummy
- Tins::DateTimeDummy
- Tins::DeepConstGet
- Tins::DeepDup
- Tins::Deflect
- Tins::Deflect::DeflectError
- Tins::Deflect::Deflector
- Tins::Deflect::DeflectorCollection
- Tins::Delegate
- Tins::DynamicScope
- Tins::DynamicScope::Context
- Tins::Eigenclass
- Tins::ExtractLastArgumentOptions
- Tins::FileBinary
- Tins::FileBinary::ClassMethods
- Tins::FileBinary::Constants
- Tins::Find
- Tins::Find::Finder
- Tins::Find::Finder::PathExtension
- Tins::FromModule
- Tins::Full
- Tins::GO
- Tins::GO::EnumerableExtension
- Tins::Generator
- Tins::HashSymbolizeKeysRecursive
- Tins::HashUnion
- Tins::IfPredicate
- Tins::InstanceExec
- Tins::Interpreter
- Tins::Limited
- Tins::LinesFile
- Tins::LinesFile::LineExtension
- Tins::Memoize
- Tins::Memoize::CacheMethods
- Tins::MethodDescription
- Tins::MethodMissingDelegator
- Tins::MethodMissingDelegator::DelegatorClass
- Tins::MethodMissingDelegator::DelegatorModule
- Tins::Minimize
- Tins::ModuleGroup
- Tins::NamedSet
- Tins::Null
- Tins::Null::Kernel
- Tins::NullClass
- Tins::NullPlus
- Tins::Once
- Tins::P
- Tins::ParameterizedModule
- Tins::PartialApplication
- Tins::ProcCompose
- Tins::ProcPrelude
- Tins::RangePlus
- Tins::RequireMaybe
- Tins::Responding
- Tins::Rotate
- Tins::Scope
- Tins::SecureWrite
- Tins::SexySingleton
- Tins::SexySingleton::SingletonClassMethods
- Tins::Shuffle
- Tins::StringByteOrderMark
- Tins::StringCamelize
- Tins::StringUnderscore
- Tins::StringVersion
- Tins::StringVersion::Version
- Tins::Subhash
- Tins::SymbolMaker
- Tins::Terminal
- Tins::ThreadGlobal
- Tins::ThreadLocal
- Tins::TimeDummy
- Tins::TimeFreezer
- Tins::To
- Tins::ToProc
- Tins::Token
- Tins::UniqBy
- Tins::Write
- Object
- Object::DSLKit
- Object::Spruz
- Array
- Date
- DateTime
- Enumerable
- File
- Hash
- IO
- IRB
- Method
- Module
- Proc
- Range
- String
- Symbol
- Time
- UnboundMethod

No matching classes.

# Module

### Public Instance Methods

memoize_function(*function_ids) click to toggle source

Automatically memoize calls of the functions `function_ids`. The memoized result does ONLY depend on the arguments given to the function.

    # File lib/tins/memoize.rb, line 65
    def memoize_function(*function_ids)
      function_ids.extend(ExtractLastArgumentOptions)
      function_ids, opts = function_ids.extract_last_argument_options
      mc = __memoize_cache__
      function_ids.each do |function_id|
        function_id = function_id.to_s.to_sym
        memoize_apply_visibility function_id do
          orig_function = instance_method(function_id)
          __send__(:define_method, function_id) do |*args|
            if mc.key?(function_id) and result = mc[function_id][args]
              result
            else
              (mc[function_id] ||= {})[args] = result = orig_function.bind(self).call(*args)
              opts[:freeze] and result.freeze
              $DEBUG and warn "#{self.class} cached function #{function_id}(#{args.inspect unless args.empty?}) = #{result.inspect}"
            end
            result
          end
        end
      end
      function_ids.size == 1 ? function_ids.first : function_ids
    end

memoize_method(*method_ids) click to toggle source

Automatically memoize calls of the the methods `method_ids`. The memoized results do NOT ONLY depend on the arguments, but ALSO on the object the method is called on.

    # File lib/tins/memoize.rb, line 36
    def memoize_method(*method_ids)
      method_ids.extend(ExtractLastArgumentOptions)
      method_ids, opts = method_ids.extract_last_argument_options
      include CacheMethods
      method_ids.each do |method_id|
        method_id = method_id.to_s.to_sym
        memoize_apply_visibility method_id do
          orig_method = instance_method(method_id)
          __send__(:define_method, method_id) do |*args|
            mc = __memoize_cache__
            if mc.key?(method_id) and result = mc[method_id][args]
              result
            else
              (mc[method_id] ||= {})[args] = result = orig_method.bind(self).call(*args)
              $DEBUG and warn "#{self.class} cached method #{method_id}(#{args.inspect unless args.empty?}) = #{result.inspect} [#{__id__}]"
              opts[:freeze] and result.freeze
            end
            result
          end
        end
      end
      method_ids.size == 1 ? method_ids.first : method_ids
    end

named(name, method, *args, &named_block) click to toggle source

    # File lib/tins/xt/named.rb, line 15
    def named(name, method, *args, &named_block)
      include Module.new {
        define_method(name) do |*rest, &block|
          block = named_block if named_block
          __send__(method, *(args + rest), &block)
        end
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.