When we try to redefine a constant, Ruby shows only a warning, but not any error. So one can always redefine a constant in Ruby?
Also a private method of a class can be invoked using the send method:
Const = 12
puts Const
#only an warning: already initialized constant Const
Const = 14
puts Const #Displays 14
class MyClass
private
def priv
puts 'In private method'
end
end
obj = MyClass.new
#Error: private method `priv' called for #<MyClass:0x7f2cfda21738> (NoMethodError)
#obj.priv
#but this is fine!
obj.send(:priv)
Are there any rationale behind such designs in Ruby? Do not these violate the basic idea of constants and access specifiers respectively?
Is there any real, practical use of these designs? Some examples would be great if there are!
Note: I do see a lot of questions/discussions here regarding Ruby's constants and private methods, but I did not find anything related to the reason behind these.