From: Brian Candler Date: 2010-10-09T20:24:55+09:00 Subject: Re: how do i add an instance variable to a class in Ruby Amit Tomar wrote: > i didn't get any error meassage but in class2.rb i tried to print @a > value using puts "#{@a}" .but got the blank o/p brian@zino:~$ cat class1.rb module Person class Amit def initialize @a=10 end end end brian@zino:~$ cat class2.rb module Person class Sumit < Amit def aos puts "#{@a}" end end end brian@zino:~$ cat run.rb require 'class1' require 'class2' me = Person::Sumit.new me.aos brian@zino:~$ ruby run.rb 10 brian@zino:~$ So it works perfectly for me. So you need to work out what's different for you. I'm running under Ubuntu Lucid x86, with this ruby version: brian@zino:~$ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] But this is such a simple piece of code that it should run the same anywhere. So I imagine your code is different. Directly copy-paste the *exact* code you are running. Directly copy-paste *exactly* what you see when you run it. Sometimes it's useful to run ruby with -w flag: i.e. ruby -w run.rb -- Posted via http://www.ruby-forum.com/.