There is an example in the book:
"Seconds/day: #{24*60*60}" # => Seconds/day: 86400
"#{'Ho! '*3}Merry Christmas!" # => Ho! Ho! Ho! Merry Christmas!
"This is line #$." # => This is line 3
But when I try to implement the third line's symbol #$ it in a separate file, it prints smth strange. Here's my file str2.rb:
puts "Hello, World #$."
puts "Hello, World #$"
puts "#$"
Now I run it (in Win XP console):
C:\ruby\sbox>ruby str2.rb Hello, World 0 Hello, World ["enumerator.so", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/i386-mingw32/enc/encdb.so", "C:/Rai lsInstaller/Ruby1.9.3/lib/ruby/1.9.1/i386-mingw32/enc/windows_1251.so", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/ 1.9.1/i386-mingw32/enc/trans/transdb.so", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/defau lts.rb", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb", "C:/RailsInstaller/Ruby1.9.3/l ib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems /exceptions.rb", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb", "C:/RailsInstaller/Ruby1.9 .3/lib/ruby/site_ruby/1.9.1/rubygems.rb", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/i386-mingw32/enc/utf_16l e.so", "C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/i386-mingw32/enc/trans/utf_16_32.so", "C:/RailsInstaller/Ru by1.9.3/lib/ruby/1.9.1/i386-mingw32/enc/trans/single_byte.so"] puts
I've found that #$. (the period is mandatory) shows the line number only in Interactive Ruby Console. Used in file it produces 0 on any line. But why all that text is printed if I use symbols like this "#$" \n "#$"?
Also such a code in a file:
puts "Hello, World #$" ## without period at the end
produces such an error:
C:\ruby\sbox>ruby str2.rb
str2.rb:3: unterminated string meets end of file
What does #$ mean? Where and how to use it?