最初のrubyプログラムで発生した問題

1763 ワード

ruby言語を使ってプログラミングする感じは、何度も驚嘆して、とても不思議なことに、私が前にc、c++などの言語でプログラミングしたときに遭遇した苦痛を何度も撫でてくれた人がいます.
次のコードは、テキストから興味のある文を選択するために、私が教材に従ってノックしたものです.

  
  
  
  
  1. text =%q{ 
  2. Ruby is a great programming language. It is object oriented 
  3. and has many groovy features. Some people don't like it, but  
  4. that's not our problem!It's easy to learn. It's great.To learn 
  5. more about Ruby,visit the official Ruby Web site today. 
  6.  
  7. sentences =text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/) 
  8. sentences_sorted =sentences.sort_by {|sentence| sentence.length} 
  9. one_third =sentences_sorted.length /3 
  10. ideal_sentences =sentences_sorted.slice(one_third, one_third +1) 
  11. ideal_sentences =ideal_sentences.select { |sentence| sentence =~ /is|are/ } 
  12. puts ideal_sentences.join("."

    #ruby summarize.rbが実行すると、bug:summarizeがポップアップされます.rb:12: syntax error, unexpected '}'.
しかし、何度も検査しても、理由は見えなかった.むしろone_thirdは直接定量をつけてOKです.原因を探し続けましょう.