I'm trying to understand this:

module A
  def a=(num)
    @a = num % 2
  end

  def b(num)
    @b = num % 2
  end
end

class B
  include A
  def initialize(num)
    a = num
    b(num)
  end
end

class C
  include A
  def initialize(num)
    self.a = num
    self.b(num)
  end
end

b = B.new 10          # => #<B:0x007ffb27497f58 @b=0>
b.instance_variables  # => [:@b]
b.a = 10              # => 10
b.instance_variables  # => [:@b, :@a]


c = C.new 10          # => #<C:0x007ffb2755e798 @a=0, @b=0>
c.instance_variables  # => [:@a, :@b]

Why the "assignment-like" method needs a "self" when the class is
initializated and the others methods don't?

Thanks!
panchiz

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