> The problem with this code is that this variable is accessible from
> outside.

Check this out:


class Dog
  def initialize
    @secret_val = 10
  end
end


d = Dog.new
puts d.secret_val

--output:--
1.rb:9:in `<main>': undefined method `secret_val' for
#<Dog:0x00000100925be8 @secret_val=10> (NoMethodError)


x = d.instance_eval("@secret_val")
puts x

--output:--
10


x = d.send(:instance_variable_get, "@secret_val")
puts x

--output:--
10



--output:--
10

-- 
Posted via http://www.ruby-forum.com/.