From: 7stud -- Date: 2012-09-20T12:36:27+09:00 Subject: Re: Class variables > 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 `
': undefined method `secret_val' for # (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/.