0

The First One

module A
  include B
  def initialize
     -----
  end
  def x
    ---------
    self << Y.new     # I need some explanation on this please
    --------
  end
end

The Second One is

class H
  include G
  include F

  EE = [.,.,.,]
  def << k     # I need some explanation here
    k.id?
    -------
  end
end

Can some one please help me out! I am a newbie to the whole kind of programming

kill007
  • 361
  • 1
  • 4
  • 13

1 Answers1

1

In both instances the << is being used as an operator.

self << Y.new is equivalent to self.send(:'<<', Y.new) so for instance if self was an Array, this would push Y.new into it.

In the second example you are defining the operator << and k is the argument .

diedthreetimes
  • 4,086
  • 26
  • 38
  • So, after pushing will it go to the next step of the same method?? – kill007 Aug 04 '11 at 18:18
  • it is a method just like any other. In the case of array it is an alias for `push`. So, yes. See this [link](http://www.tutorialspoint.com/ruby/ruby_operators.htm) for more info on operators. – diedthreetimes Aug 04 '11 at 19:07