Skip to content

Commit

Permalink
Round 3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobEvelyn committed Sep 14, 2021
1 parent 229df4a commit bf94391
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/memo_wise.rb
Expand Up @@ -193,12 +193,14 @@ def #{method_name}
# another_single_arg_method_name: 0
# }
# }
@_memo_wise_indices ||= Hash.new { |h, k| h[k] = {} }
@_memo_wise_index_counters ||= Hash.new(0)

index = @_memo_wise_index_counters[klass]
@_memo_wise_indices[klass][method_name] = index
@_memo_wise_index_counters[klass] += 1
memo_wise_indices = klass.instance_variable_get(:@_memo_wise_indices)
memo_wise_indices ||= klass.instance_variable_set(:@_memo_wise_indices, Hash.new { |h, k| h[k] = {} })
memo_wise_index_counters = klass.instance_variable_get(:@_memo_wise_index_counters)
memo_wise_index_counters ||= klass.instance_variable_set(:@_memo_wise_index_counters, Hash.new(0))

index = memo_wise_index_counters[klass]
memo_wise_indices[klass][method_name] = index
memo_wise_index_counters[klass] += 1

key = method.parameters.first.last

Expand Down
4 changes: 1 addition & 3 deletions lib/memo_wise/internal_api.rb
Expand Up @@ -192,9 +192,7 @@ def initialize(target)
# @return [Integer] the array index in `@_memo_wise_single_argument` to use
# to find the memoization data for the given method
def index(method_name)
indices = target_class.instance_variable_get(:@_memo_wise_indices) ||
target.instance_variable_get(:@_memo_wise_indices)
indices[target_class][method_name]
target_class.instance_variable_get(:@_memo_wise_indices)[target_class][method_name]
end

# Returns visibility of an instance method defined on class `target`.
Expand Down

0 comments on commit bf94391

Please sign in to comment.