Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Memoizable doesn't memoize overriden methods

#3162
class Foo
  extend ActiveSupport::Memoizable
  def foo() end
  memoize :foo
end

class Bar < Foo
  def foo() puts "In Bar#foo" end
  # memoize :foo
end

bar = Bar.new
bar.foo
bar.foo

The above snippet prints In Bar#foo twice, which means the overridden foo method isn't memoized.
Uncommenting the memoize :foo statement in Bar throws a Already memoized foo error so achieving memoization of an overriden method sounds impossible.

Unless it's the desired behavior, we could either memoize an overriden memoized method by default, or allow a second call to memoize in the subclass context.

Thanks for making web development awesome !

Reported by Samuel Lebeau · September 8th, 2009 @ 02:09 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
  2. Elomar França
    Elomar França
    • Tag changed from bugmash to activesupport, bugmash, memoizable

    +1, verified.

    In this case, memoization would only work if Bar#foo called super.

    I've attached a patch with a failing test, applies on 2-3-stable and master.

    September 27th, 2009 @ 08:06 PM

  3. John Pignata
    John Pignata
    • Tag changed from activesupport, bugmash, memoizable to activesupport, bugmash, memoizable, patch

    I've tried several approaches to allow this, notably functionality such as tracking memoized methods using an instance hash and method_added trickery to figure out when a method was overridden. Nothing appears to work across all cases well.

    My attached patch for master adds an option hash to memoize. If :force => true is passed in this hash, memoize will not raise an error. This will allow a developer who encounters this edge case to work around it.

    September 28th, 2009 @ 05:44 AM

  4. Rizwan Reza
    Rizwan Reza
    • Tag changed from activesupport, bugmash, memoizable, patch to activesupport, memoizable, patch

    February 12th, 2010 @ 12:46 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:55 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:55 PM