Why there is no need to have protected_constant in Ruby?

Hi,

While I was reading the topic - Chain of responsibility pattern, I found
one
example(Chain-of-responsibility pattern - Wikipedia),
which I’m trying to write in
Ruby. This is a part of the example given there.

abstract class PurchasePower {
protected static final double BASE = 500;
protected PurchasePower successor;

public void setSuccessor(PurchasePower successor) {
    this.successor = successor;
}

abstract public void processRequest(PurchaseRequest request);

}

But, while writing code in Ruby to convert the above, I got confused
when I
saw the protected static final double BASE = 500;. Now, as In Ruby no
such
method called protected_constant exist, what else way I should write it?

Why in Ruby protected_constant doesn’t exist, but private constant and
public_constant does ?

Regards,
Arup R.

Debugging is twice as hard as writing the code in the first place.
Therefore,
if you write the code as cleverly as possible, you are, by definition,
not
smart enough to debug it.

–Brian Kernighan

In ruby there is only public and private. A constant is not meant to be
modified. You can but the interpreter will complain. There is no
protected
as there is in Java. There is no one to one translation from Java to
ruby.
This is just one of the differences in the language.

On Wed, Dec 10, 2014 at 10:15 PM, D. Deryl D. [email protected]
wrote:

In ruby there is only public and private. A constant is not meant to be
modified. You can but the interpreter will complain.

Right.

There is no protected as there is in Java.

Wrong.

$ ruby -e ‘class Foo; def x; p bar; end; protected; def bar; 123; end;
end; Foo.new.x’
123
$ ruby -e ‘class Foo; def x; p bar; end; protected; def bar; 123; end;
end; Foo.new.x; Foo.new.bar’
123
-e:1:in <main>': protected method bar’ called for
#Foo:0x00000600425b20 (NoMethodError)

There is no one to one translation from Java to ruby.

Right.

Cheers

robert