Q:

A variable/constant that inherits but does not share with the superclass, and does not share namespace

Is there a way to introduce some variable/constant with the the following three properties?

a) It inherits a superclass's value when it is not assigned in the own class.
b) It does not inherit other classes's value other than for superclasses's (even if they share the namespace).
c) It does not overwrite the superclasses's value when assigned in the own class.

Using a class instance variable, a) is not satisfied.
class A; @foo = :foo end
class B < A; @foo end # => nil  (Does not satisfy (a))
class A; class C; @foo end end # => nil (Satisfies (b))

class B < A; @foo = :bar end
class A; @foo end # => :foo  (Satisfies (c))

Using a class variable, c) is not satisfied.
class A; @@foo = :foo end
class B < A; @@foo end # => :foo  (Satisfies (a))
class A; class C; @foo end end # => NameError (Satisfies (b))

class B < A; @@foo = :bar end
class A; @foo end # => :bar  (Does not satisfy (c))

Using a constant, b) is not satisfied.
class A; Foo = :foo end
class B < A; Foo end # => :foo  (Satisfies (a))
class A; class C; Foo end end # => :foo (Does not satisfy (b))

class B < A; Foo = :bar end
class A; Foo end # => :foo  (Satisfies (c))

I want something that behaves like this:
class A; something = :foo end
class B < A; something end # => :foo  (Satisfies (a))
class A; class C; something end end # => nil or Error (Satisfies (b))

class B < A; something = :bar end
class A; something end # => :foo  (Satisfies (c))

If it cannot be done simply by assigning and referencing a variable/constant, then is there any way to implement accessor methods that would have this property?

A:

You'll need to create your own kind of accessor with the specific properties that you want. For example,
module InheritableProperty
  def property
    @property || superclass.property
  end
  def property=(value)
    @property = value
  end
end

class A
  extend InheritableProperty
end
class B < A
  extend InheritableProperty
  class C
    extend InheritableProperty
  end
end

A.property = 1
A.property # => 1
B.property # => 1
B::C.property # error

A.property = 1
B.property = 2
A.property # => 1
B.property # => 2
B::C.property # error

A.property = 1
B.property = 2
B::C.property = 3
A.property # => 1
B.property # => 2
B::C.property # => 3

