module Memorandum
Constants
- MEMORANDUM_MEMOIZED
- MEMORANDUM_SPECIAL_CHARACTERS
- MEMORANDUM_STATUSES
- MEMORANDUM_UNMEMOIZED
- MEMORANDUM_VALUES
- VERSION
Public Class Methods
extended(base)
click to toggle source
# File lib/memorandum.rb, line 4 def self.extended base base.send :include, InstanceMethods end
Public Instance Methods
memo(*arguments)
click to toggle source
# File lib/memorandum.rb, line 8 def memo *arguments name = arguments.pop flags = arguments memoized_statuses = memorandum_ivar_name MEMORANDUM_STATUSES, name memoized_values = memorandum_ivar_name MEMORANDUM_VALUES, name unmemoized_name = "#{MEMORANDUM_UNMEMOIZED}_#{name}" access = find_access name alias_method unmemoized_name, name define_method name do |*args| statuses = memorandum_fetch memoized_statuses, Hash[] values = memorandum_fetch memoized_values, Hash[] unless statuses[args] value = send unmemoized_name, *args value = value.freeze if flags.include? :freeze value = IceNine.deep_freeze value if flags.include? :deep_freeze values[args] = value statuses[args] = true end values[args] end send access, name send access, unmemoized_name end
memorandum_ivar_name(name, method_name)
click to toggle source
# File lib/memorandum.rb, line 41 def memorandum_ivar_name name, method_name "@#{MEMORANDUM_MEMOIZED}_#{name}_for_#{method_name}".tap do |result| MEMORANDUM_SPECIAL_CHARACTERS.each do |special_character, replacement| result.gsub! special_character, replacement end end end
Private Instance Methods
find_access(method_name)
click to toggle source
# File lib/memorandum.rb, line 74 def find_access method_name case when private_instance_methods.include?(method_name.to_sym) then :private when protected_instance_methods.include?(method_name.to_sym) then :protected when public_instance_methods.include?(method_name.to_sym) then :public else :unknown end end