Ruby 末尾にある改行を取り除くサンプル

環境
Windows11 pro 64bit
ruby 3.0.3p157

構文
改行を除去するには「chomp」を使用します。
open(“ファイル名").each do |line|
p line.chomp

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
open("data.txt").each do |line|
p line.chomp
end
open("data.txt").each do |line| p line.chomp end
open("data.txt").each do |line|
  p line.chomp
end

 

IT

Posted by arkgame