Introduction

You can read an I/O stream with each using a custom delimiter of your choosing:

Demo

File.open("main.rb").each(',') { |line| puts line }

Result

Here, you passed an optional argument to each that specified a Comma from the default "newline" delimiter.

You can override the default delimiter by setting the special variable $/ to any delimiter you choose.

Related Topic