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.

Teach ActiveSupport::Memoizable about private methods

#2138

Currently, if you define a private method and later call memoize :your_method, the replacement methods created by Memoizable will be public. E.g.


class Person
  extend ActiveSupport::Memoizable
  private
  def is_bald?; end
  memoize :is_bald?
end

Person.new.is_bald?

will not raise *NoMethodError: private method is_bald?' called*.

The attached patch causes ActiveSupport::Memoizable to prepend all the re-definition of your_method with the private keyword if the original your_method had been a private_instance_method in the first place.

Tests are included.

Reported by Niels Ganser · March 5th, 2009 @ 06:48 PM

State: resolved
Milestone: none
Assigned to: Pratik Pratik
Importance: Medium

Activity

  1. Ryan Angilly
    Ryan Angilly

    +1

    I've never memoized a private method, but would expect it to stay private.

    March 6th, 2009 @ 12:07 AM

  2. José Valim
  3. Pratik
    Pratik
    • Assigned user set to Pratik
    • Milestone cleared.

    March 6th, 2009 @ 02:41 PM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [c67d25e3c4e636d7c94909a7398231a634accf46]) Ensure ActiveSupport::Memoizable respects private methods. [#2138 Teach ActiveSupport::Memoizable about private methods state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 6th, 2009 @ 02:44 PM