Sha256: d1f546480b740bdc5701503dc5608337a869ba3ca2ac5fec1fe3b1ab4ffb07da

Contents?: true

Size: 611 Bytes

Versions: 41

Compression:

Stored size: 611 Bytes

Contents

1つの文字列を受け取り、文字列と一致するファイル名のテキストデータを1行ずつ読み取り、表示するプログラムを作成せよ。


- file.each_line

file = File.open(ファイル名)
file.each_line do |変数|
  繰り返したい処理
end
file.close

each_lineメソッドはファイルの各行をそれぞれ処理するメソッド。
ファイルを1行ずつ読み込み、処理を繰り返す。

open,closeメソッドはそれぞれファイルを読み込むためにファイルを開くメソッド、開いたファイルを閉じるメソッド。

Version data entries

41 entries across 24 versions & 1 rubygems

Version Path
ruby_learner-1.2.9 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.8 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.7 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.6 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.5 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.4 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.3 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.2 contents/questions/sequential_check/section_10/part_2/lib/sentence.org
ruby_learner-1.2.2 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.1 contents/questions/sequential_check/section_10/part_2/lib/sentence.org
ruby_learner-1.2.1 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.0 contents/takahashi/sample_prog/question/9_2.org
ruby_learner-1.2.0 contents/questions/sequential_check/section_9/part_2/lib/sentence.org
ruby_learner-1.1.15 takahashi/sample_prog/question/9_2.org
ruby_learner-1.1.15 questions/sequential_check/section_9/part_2/lib/sentence.org
ruby_learner-1.1.14 takahashi/sample_prog/question/9_2.org
ruby_learner-1.1.14 questions/sequential_check/section_9/part_2/lib/sentence.org
ruby_learner-1.1.13 questions/sequential_check/section_9/part_2/lib/sentence.org
ruby_learner-1.1.13 takahashi/sample_prog/question/9_2.org
ruby_learner-1.1.11 takahashi/sample_prog/question/9_2.org