Skip to content

Commit

Permalink
Merge pull request #15 from TINYhr/master
Browse files Browse the repository at this point in the history
Give double-memoize errors their own error class
  • Loading branch information
matthewrudy committed Apr 16, 2014
2 parents f81f8f2 + 44cfee0 commit a27eb18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/memoist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def memoize(*method_names)
include InstanceMethods

if method_defined?(unmemoized_method)
raise "Already memoized #{method_name}"
raise AlreadyMemoizedError.new("Already memoized #{method_name}")
end
alias_method unmemoized_method, method_name

Expand Down Expand Up @@ -194,4 +194,6 @@ def #{method_name}(*args)
end
end
end

class AlreadyMemoizedError < RuntimeError; end
end
2 changes: 1 addition & 1 deletion memoist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.date = "2013-07-19"
s.email = ["josh@joshpeek.com", "tarmo@itech.ee", "jeremy@bitsweat.net", "libc@mac.com", "fxn@hashref.com", "niels@herimedia.co", "wycats@gmail.com", "jeem@hughesorama.com", "john.pignata@gmail.com", "42@dmathieu.com", "jose.valim@gmail.com"]
s.extra_rdoc_files = ["README.md"]
s.files = ["README.md", "test/benchmark/memoist_benchmark.rb", "test/memoist_test.rb", "test/test_helper.rb", "lib/memoist/core_ext/singleton_class.rb", "lib/memoist.rb"]
s.files = ["README.md", "test/memoist_test.rb", "test/test_helper.rb", "lib/memoist/core_ext/singleton_class.rb", "lib/memoist.rb"]
s.homepage = "https://github.com/matthewrudy/memoist"
s.licenses = ["MIT"]
s.rdoc_options = ["--main", "README.md"]
Expand Down
6 changes: 3 additions & 3 deletions test/memoist_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ def test_object_memoized_module_methods
end

def test_double_memoization
assert_raise(RuntimeError) { Person.memoize :name }
assert_raise(Memoist::AlreadyMemoizedError) { Person.memoize :name }
person = Person.new
person.extend Memoist
assert_raise(RuntimeError) { person.memoize :name }
assert_raise(Memoist::AlreadyMemoizedError) { person.memoize :name }

company = Company.new
company.extend Memoist
company.memoize :name
assert_raise(RuntimeError) { company.memoize :name }
assert_raise(Memoist::AlreadyMemoizedError) { company.memoize :name }
end

def test_double_memoization_with_identifier
Expand Down

0 comments on commit a27eb18

Please sign in to comment.