书中有一个例子:
"Seconds/day: #{24*60*60}" # => Seconds/day: 86400
"#{'Ho! '*3}Merry Christmas!" # => Ho! Ho! Ho! Merry Christmas!
"This is line #$." # => This is line 3
但是当我尝试#$
在一个单独的文件中实现第三行的符号时,它会打印出奇怪的东西。这是我的文件str2.rb
:
puts "Hello, World #$."
puts "Hello, World #$"
puts "#$"
现在我运行它(在 Win XP 控制台中):
C:\ruby\sbox>ruby str2.rb 你好,世界 0 你好,世界 ["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"] 看跌期权
我发现#$.
(该句点是强制性的)仅在交互式 Ruby 控制台中显示行号。用于它0
在任何行上生成的文件。但是,如果我使用这样的符号,为什么会打印所有这些文本"#$" \n "#$"
?
文件中还有这样的代码:
puts "Hello, World #$" ## without period at the end
产生这样的错误:
C:\ruby\sbox>ruby str2.rb
str2.rb:3: unterminated string meets end of file
是什么#$
意思?在哪里以及如何使用它?