-1
likedict={linux:3,web:2}
likedict[:linux]++
likedict[:linux]
# => 6 
likedict[:web]
# => 2 

I figured out that likedict[:linux]+=1 is what I want. This is my test case. I expected likedict[:linux] to become 4 after I do likedict[:linux]++, but it is 6. Why is that?

sawa
  • 165,429
  • 45
  • 277
  • 381
BufBills
  • 8,005
  • 12
  • 48
  • 90
  • 1
    what you have done is `likedict[:linux] + likedict[:linux]` ruby does not support `++` use `+= 1` if you need to increment – bjhaid Feb 11 '14 at 23:50

1 Answers1

5

In Ruby there is no ++ operation.

If you look carefully after you do likedict[:linux]++ it still expects more for your statement, and then you entered likedict[:linux], so 3 + 3 = 6.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
sonnyhe2002
  • 2,091
  • 3
  • 19
  • 31