--ggHp9WSrPOeNxb0b Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This makes complete sense and was what I thought was happening. None-the-less it was still a decent gotcha that I wasn't expecting. This was a very helpful response, thank you. Maybe this code snippet could make its way into the next Programming Ruby book. ;~) -sc > > class Testing > > @test_hash = Hash.new() > > > > public > > def set(key, val) > > @test_hash[key] = val > > end > > end > > That's a Java idiom that doesn't mean the same thing in Ruby. In a class > definition, outside of a method definition, you are in the context of the > *class* object, not the instance. So what you're doing there is defining > a class instance variable (sort of, but not really at all, like a static > variable in Java), whereas when you did it inside the initialize method > you were defining an instance variable. > > This is confusing. The short answer is, do it in the initialize instead. > > For a start at the long answer, try this: > > class Testing > > @var = "class" > > def initialize > @var = "instance" > end > > def Testing.print > puts @var > end > > def print > puts @var > end > end > > t = Testing.new > t.print > Testing.print -- Sean Chittenden --ggHp9WSrPOeNxb0b Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: Sean Chittenden <sean / chittenden.org> iEYEARECAAYFAjtMB7AACgkQn09c7x7d+q2a0QCfdChyTj/KGykiuoG6wbV/gUXl WtIAn2T9KqnxKV+vFQn/6ijLKvEce5HN Wu -----END PGP SIGNATURE----- --ggHp9WSrPOeNxb0b--