Module: Unparser::Adamantium::ModuleMethods

Defined in:
lib/unparser/adamantium.rb

Overview

Methods mixed in to adamantium modules

Instance Method Summary collapse

Instance Method Details

#memoize(*methods) ⇒ self

Memoize a list of methods

Parameters:

  • methods (Array<#to_s>)

    a list of methods to memoize

Returns:

  • (self)


96
97
98
99
# File 'lib/unparser/adamantium.rb', line 96

def memoize(*methods)
  methods.each(&method(:memoize_method))
  self
end

#memoized?(method_name) ⇒ Bool

Test if method is memoized

Parameters:

  • name (Symbol)

Returns:

  • (Bool)


106
107
108
# File 'lib/unparser/adamantium.rb', line 106

def memoized?(method_name)
  memoized_methods.key?(method_name)
end

#unmemoized_instance_method(method_name) ⇒ UnboundMethod

Return unmemoized instance method

Parameters:

  • name (Symbol)

Returns:

  • (UnboundMethod)

    the memoized method

Raises:

  • (NameError)

    raised if the method is unknown



121
122
123
124
125
# File 'lib/unparser/adamantium.rb', line 121

def unmemoized_instance_method(method_name)
  memoized_methods.fetch(method_name) do
    fail ArgumentError, "##{method_name} is not memoized"
  end
end