This project is archived and is in readonly mode.

#3162 ✓stale
Samuel Lebeau

Memoizable doesn't memoize overriden methods

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

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

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

bar =

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 !

Comments and changes to this ticket

  • CancelProfileIsBroken
  • Elomar França

    Elomar França September 27th, 2009 @ 08:06 PM

    • 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.

  • John Pignata

    John Pignata September 28th, 2009 @ 05:44 AM

    • 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.

  • Rizwan Reza

    Rizwan Reza February 12th, 2010 @ 12:46 PM

    • Tag changed from activesupport, bugmash, memoizable, patch to activesupport, memoizable, patch
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:55 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:55 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket