From 7c365cb700dace08322e0f926b83c80bb87c69f7 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Mon, 25 Aug 2008 10:33:03 +0100 Subject: [PATCH] :memoized methods are stored in Klass.memoized_methods --- activesupport/lib/active_support/memoizable.rb | 4 ++++ activesupport/test/memoizable_test.rb | 5 +++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index 6506238..cfc7d67 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -6,6 +6,9 @@ module ActiveSupport unless base.method_defined?(:freeze_without_memoizable) alias_method_chain :freeze, :memoizable end + def self.memoized_methods + @memoized_methods ||= [] + end end end @@ -46,6 +49,7 @@ module ActiveSupport include Freezable raise "Already memoized #{symbol}" if method_defined?(:#{original_method}) + self.memoized_methods << :#{symbol} alias #{original_method} #{symbol} if instance_method(:#{symbol}).arity == 0 diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb index 135d56f..f128f92 100644 --- a/activesupport/test/memoizable_test.rb +++ b/activesupport/test/memoizable_test.rb @@ -114,6 +114,11 @@ uses_mocha 'Memoizable' do assert_equal "Josh", @person.name assert_raise(ActiveSupport::FrozenObjectError) { @person.name.gsub!("Josh", "Gosh") } end + + def test_memoized_methods + assert_operator Person.memoized_methods, :include?, :name? + assert_equal [:fib, :counter], Calculator.memoized_methods + end def test_reloadable counter = @calculator.counter -- 1.5.4.3