Starting with Java, I am trying to implement LinkedList in Ruby. The usual way to implement this in Java is with a class called LinkedList and a private inner class called Node with each LinkedList object as a Node object.
class LinkedList
private
class Node
attr_accessor :val, :next
end
end
I do not want to disclose the Node class to the outside world. However, with this setting in Ruby, I can access the private object of the Node class outside the LinkedList class using this -
node = LinkedList::Node.new
I know that with Ruby 1.9 we can use the private_constant method to designate Node as a private constant. But I wonder if this is the right thing to do? Also, why can I create Node objects outside the LinkedList class, even if it is declared as private?