最初のrubyプログラムで発生した問題
1763 ワード
ruby言語を使ってプログラミングする感じは、何度も驚嘆して、とても不思議なことに、私が前にc、c++などの言語でプログラミングしたときに遭遇した苦痛を何度も撫でてくれた人がいます.
次のコードは、テキストから興味のある文を選択するために、私が教材に従ってノックしたものです.
#ruby summarize.rbが実行すると、bug:summarizeがポップアップされます.rb:12: syntax error, unexpected '}'.
しかし、何度も検査しても、理由は見えなかった.むしろone_thirdは直接定量をつけてOKです.原因を探し続けましょう.
次のコードは、テキストから興味のある文を選択するために、私が教材に従ってノックしたものです.
- text =%q{
- Ruby is a great programming language. It is object oriented
- and has many groovy features. Some people don't like it, but
- that's not our problem!It's easy to learn. It's great.To learn
- more about Ruby,visit the official Ruby Web site today.
- }
-
- sentences =text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/)
- sentences_sorted =sentences.sort_by {|sentence| sentence.length}
- one_third =sentences_sorted.length /3
- ideal_sentences =sentences_sorted.slice(one_third, one_third +1)
- ideal_sentences =ideal_sentences.select { |sentence| sentence =~ /is|are/ }
- puts ideal_sentences.join(".")
#ruby summarize.rbが実行すると、bug:summarizeがポップアップされます.rb:12: syntax error, unexpected '}'.
しかし、何度も検査しても、理由は見えなかった.むしろone_thirdは直接定量をつけてOKです.原因を探し続けましょう.