Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ruby每行比较只返回最后一个字符串_Ruby - Fatal编程技术网

ruby每行比较只返回最后一个字符串

ruby每行比较只返回最后一个字符串,ruby,Ruby,代码: 我希望代码返回include?的所有实例,但是当代码运行时,wordList只包含words.txt的最后一行(“onetwotree.”)。为什么words.txt中的其他行不被分解呢?因为您希望找到的所有其他行的末尾都有“隐藏”的换行符。你可以自己看 one blah-blah-blah 123-5342-123123 onetwo onetwothree onetwothreefour 您可以使用chomp来删除换行符方法在行 File.foreach('words.txt')

代码:


我希望代码返回include?的所有实例,但是当代码运行时,wordList只包含words.txt的最后一行(“onetwotree.”)。为什么words.txt中的其他行不被分解呢?

因为您希望找到的所有其他行的末尾都有“隐藏”的换行符。你可以自己看

one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用
chomp来删除换行符方法在

File.foreach('words.txt') do |line|
  puts line.inspect
  # or
  p line
end

由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看

one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用
chomp来删除换行符方法在

File.foreach('words.txt') do |line|
  puts line.inspect
  # or
  p line
end

由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看

one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用
chomp来删除换行符方法在

File.foreach('words.txt') do |line|
  puts line.inspect
  # or
  p line
end

由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看

one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用
chomp来删除换行符方法在

File.foreach('words.txt') do |line|
  puts line.inspect
  # or
  p line
end