Take a look at code bellow:

module Parent1
  def initialize
    @loc1 = 1
    @loc2 = 2
  end
end

class Parent2
  def initialize
    @loc3 = 3
    @loc4 = 4
  end

  def displayp2
    puts @loc3
    puts @loc4
  end
end

class Child < Parent2
  include Parent1
  def displayc
    puts @loc1
    puts @loc2
    puts @loc3
    puts @loc4
  end
end


c = Child.new
c.displayc


I was thinking of something similar to multiple inheritance and my
expectaions was that all of local variables will be available in Child
class.
What I discovered that when you add
include Parent1
line to Child class @loc3 and @loc4 disappears.
When you comment this line @loc3 and @loc4 are available in Child class.

My question is why this work that way and how to get all of @loc
available in Child class?

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