Skip to content

Commit

Permalink
Merge pull request #24 from matthewrudy/return-symbol-from-memoize
Browse files Browse the repository at this point in the history
Make memoize return a :symbol
  • Loading branch information
matthewrudy committed Aug 13, 2014
2 parents 2ab0dcc + 4c98b82 commit d4f5590
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/memoist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def #{method_name}(*args)
end
end
end
# return a chainable method_name symbol if we can
method_names.length == 1 ? method_names.first : method_names
end

class AlreadyMemoizedError < RuntimeError; end
Expand Down
9 changes: 9 additions & 0 deletions test/memoist_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ def test_memoization_with_a_subclass
assert_equal 1, student.name_calls
end

def test_memoization_is_chainable
klass = Class.new do
def foo; "bar"; end
end
klass.extend Memoist
chainable = klass.memoize :foo
assert_equal :foo, chainable
end

def test_protected_method_memoization
person = Person.new

Expand Down

0 comments on commit d4f5590

Please sign in to comment.