Peter Black Peter Black - 5 months ago 9
Ruby Question

What does $/ mean in Ruby?

I was reading about Ruby serialization ( and came across the following code. What does $/ mean? I assume $ refers to an object?

array = []
$/="\n\n""/home/alan/tmp/blah.yaml", "r").each do |object|
array << YAML::load(object)


$/ is a pre-defined variable. It's used as the input record separator, and has a default value of "\n".

Functions like gets uses $/ to determine how to separate the input. For example:

str = gets
puts str

So you have to enter ENTER twice to end the input for str.

Reference: Pre-defined variables