What does “+=” (plus equals) mean?

前端 未结 4 1093
滥情空心
滥情空心 2020-12-09 01:43

I am doing some ruby exercises and it said I need to go back and rewrite the script with += shorthand notations.

This exercise deals primarily with lear

4条回答
  •  渐次进展
    2020-12-09 02:15

    You should look for a good book about Ruby, e.g. http://pragprog.com/book/ruby3/programming-ruby-1-9

    The first 150 pages cover most of the basic things about Ruby.

    str = "I want to learn Ruby"
    
    i = 0
    str.split.each do |word|
      i += 1
    end
    
    puts "#{i} words in the sentence \"#{str}\""
    
      => 5 words in the sentence "I want to learn Ruby"
    

提交回复
热议问题