Permalink
Browse files

rename to Memoizer

  • Loading branch information...
matthewrudy committed Dec 7, 2011
1 parent 35fe922 commit 06ee8cfe42c82203892d41f2103ed0ef64325bb2
Showing with 12 additions and 12 deletions.
  1. +4 −4 lib/{memoizable.rb → memoizer.rb}
  2. +8 −8 test/{memoizable_test.rb → memoizer_test.rb}
@@ -1,7 +1,7 @@
# require 'active_support/core_ext/kernel/singleton_class'
require 'core_ext/singleton_class'
-module Memoizable
+module Memoizer
def self.memoized_ivar_for(symbol)
"@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
@@ -37,7 +37,7 @@ def prime_cache(*syms)
if method(m).arity == 0
__send__($1)
else
- ivar = Memoizable.memoized_ivar_for($1)
+ ivar = Memoizer.memoized_ivar_for($1)
instance_variable_set(ivar, {})
end
end
@@ -49,7 +49,7 @@ def flush_cache(*syms)
syms.each do |sym|
(methods + private_methods + protected_methods).each do |m|
if m.to_s =~ /^_unmemoized_(#{sym.to_s.gsub(/\?\Z/, '\?')})/
- ivar = Memoizable.memoized_ivar_for($1)
+ ivar = Memoizer.memoized_ivar_for($1)
instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
end
end
@@ -60,7 +60,7 @@ def flush_cache(*syms)
def memoize(*symbols)
symbols.each do |symbol|
original_method = :"_unmemoized_#{symbol}"
- memoized_ivar = Memoizable.memoized_ivar_for(symbol)
+ memoized_ivar = Memoizer.memoized_ivar_for(symbol)
class_eval <<-EOS, __FILE__, __LINE__ + 1
include InstanceMethods # include InstanceMethods
@@ -1,9 +1,9 @@
require 'test_helper'
-require 'memoizable'
+require 'memoizer'
-class MemoizableTest < Test::Unit::TestCase
+class MemoizerTest < Test::Unit::TestCase
class Person
- extend Memoizable
+ extend Memoizer
attr_reader :name_calls, :age_calls, :is_developer_calls, :name_query_calls
@@ -66,7 +66,7 @@ def name
end
module Rates
- extend Memoizable
+ extend Memoizer
attr_reader :sales_tax_calls
def sales_tax(price)
@@ -78,7 +78,7 @@ def sales_tax(price)
end
class Calculator
- extend Memoizable
+ extend Memoizer
include Rates
attr_reader :fib_calls
@@ -216,7 +216,7 @@ def test_memoization_with_boolean_arg
def test_object_memoization
[Company.new, Company.new, Company.new].each do |company|
- company.extend Memoizable
+ company.extend Memoizer
company.memoize :name
assert_equal "37signals", company.name
@@ -250,11 +250,11 @@ def test_object_memoized_module_methods
def test_double_memoization
assert_raise(RuntimeError) { Person.memoize :name }
person = Person.new
- person.extend Memoizable
+ person.extend Memoizer
assert_raise(RuntimeError) { person.memoize :name }
company = Company.new
- company.extend Memoizable
+ company.extend Memoizer
company.memoize :name
assert_raise(RuntimeError) { company.memoize :name }
end

0 comments on commit 06ee8cf

Please sign in to comment.