This project is archived and is in readonly mode.
class_inheritable_accessor should let subclasses inherit from the superclass's attribute
-
Neeraj Singh
- Tag set to activesupport, patch, rails3
This is expected behavior. I found following test.
def test_inheritance @klass.class_inheritable_accessor :a @klass.a = 'a' @sub = eval("class FlogMe < @klass; end; FlogMe") @klass.class_inheritable_accessor :b assert_respond_to @sub, :a assert_respond_to @sub, :b assert_equal @klass.a, @sub.a assert_equal @klass.b, @sub.b assert_equal 'a', @sub.a assert_nil @sub.b @klass.b = 'b' assert_not_equal @klass.b, @sub.b assert_equal 'b', @klass.b assert_nil @sub.b @sub.a = 'A' assert_not_equal @klass.a, @sub.a assert_equal 'a', @klass.a assert_equal 'A', @sub.a @sub.b = 'B' assert_not_equal @klass.b, @sub.b assert_equal 'b', @klass.b assert_equal 'B', @sub.b endAs you can see
@klass.b = 'b' assert_not_equal @klass.b, @sub.bI am adding two lines to the doc to make it clear that child copies attributes from parents when subclass is created.
-
Neeraj Singh
This ticket can be closed. I have update the doc.
-
Rizwan Reza
- No changes were found…
-
Rizwan Reza
- State changed from new to resolved
-
Thomas LECAVELIER
- Assigned user set to Rizwan Reza
Thanks for your documentation update. It states very clearly the implementation rationale.
However, I believe that implementation violates the Principle of Least Surprise, and that the behavior, despite being documented and tested, is not expected.
What do you think?
