This project is archived and is in readonly mode.

#959 ✓stale
Gaius Centus Novus

models' respond_to? does not honor private

Reported by Gaius Centus Novus | September 2nd, 2008 @ 11:14 PM | in 2.x

I want to make an attribute truly private, so I tried this:

class Foo < ActiveRecord::Base
  # attribute bar
  private
  def bar
    read_attribute :bar
  end
  def bar=(value)
    write_attribute :bar, value
  end
end

but Foo.new.respond_to?(:bar) returns true, where a normal (non-active-record) instance would return false for private methods.

This patch adds a check in respond_to? to honor private methods that shadow attributes.

Comments and changes to this ticket

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages