tags:

views:

47

answers:

1

Hi all,

I have one file named class1.rb this is structure

module Person
  class Amit
    def initialize
      @a=10
    end
  end 
end

another file named class2.rb

module Person 
  class Sumit < Amit
    def aos
      puts "#{@a}"
    end
  end
end

i am not able to acess variable @a in Sumit how do i do that??

+1  A: 

You may have a look here(adding-an-instance-variable-to-a-class-in-ruby).

kfl62
Arkkyu am not getting en error
AMIT
but am not able to access this variale @a
AMIT
I don't understand your question `s = Person::Sumit.new` and `s.aos` => `10`
kfl62
`s.instance_variable_get "@a"` => `10`
kfl62
`s.instance_variable_set "@a", 15` and `s.aos`=> `15`
kfl62