0

I was reading through the documentation for Enumerator and I ran across this example:

fib = Enumerator.new do |y|
  a = b = 1
  loop do
    y << a
    a, b = b, a + b
  end
end

Everything makes sense to me except for this line: a, b = b, a + b. Could somebody please explain what's happening?

LandonSchropp
  • 10,084
  • 22
  • 86
  • 149

1 Answers1

2

It's a parallel assignment pattern which you can see in many languages including ruby probably you will find this helpful Parallel Assignment operator in Ruby

Community
  • 1
  • 1
Miad Abrin
  • 952
  • 7
  • 14