私は現在、本「Learning Ruby the Hard Way」から Ruby を独学しようとしていますが、演習を行っているときに、「ri File.open」を実行してドキュメントを読むように言われました。それを行った後、どのプログラムからも File.open を実行できませんでした。そうするたびに、次のメッセージが表示されます。
Heres your file: ex15_sample.txt
= File.open
(from ruby core)
------------------------------------------------------------------------------
File.open(filename, mode="r" [, opt]) -> file
File.open(filename [, mode [, perm]] [, opt]) -> file
File.open(filename, mode="r" [, opt]) {|file| block } -> obj
File.open(filename [, mode [, perm]] [, opt]) {|file| block } -> obj
------------------------------------------------------------------------------
With no associated block, File.open is a synonym for File.new. If the optional
code block is given, it will be passed the opened file as an argument, and the
File object will automatically be closed when the block terminates. In this
instance, File.open returns the value of the block.
See IO.new for a list of values for the opt parameter.
Ill also ask you to type it again:
> ^Cex15.rb:13:in `gets': Interrupt
from ex15.rb:13:in `<main>'
amelia@Amelia:~/Documents$ clear
amelia@Amelia:~/Documents$ ruby ex15.rb ex15_sample.txt
Here's your file: ex15_sample.txt
= File.open
(from ruby core)
------------------------------------------------------------------------------
File.open(filename, mode="r" [, opt]) -> file
File.open(filename [, mode [, perm]] [, opt]) -> file
File.open(filename, mode="r" [, opt]) {|file| block } -> obj
File.open(filename [, mode [, perm]] [, opt]) {|file| block } -> obj
------------------------------------------------------------------------------
With no associated block, File.open is a synonym for File.new. If the optional
code block is given, it will be passed the opened file as an argument, and the
File object will automatically be closed when the block terminates. In this
instance, File.open returns the value of the block.
See IO.new for a list of values for the opt parameter.
Ill also ask you to type it again:
> ex15_sample.txt
= File.open
(from ruby core)
------------------------------------------------------------------------------
File.open(filename, mode="r" [, opt]) -> file
File.open(filename [, mode [, perm]] [, opt]) -> file
File.open(filename, mode="r" [, opt]) {|file| block } -> obj
File.open(filename [, mode [, perm]] [, opt]) {|file| block } -> obj
------------------------------------------------------------------------------
With no associated block, File.open is a synonym for File.new. If the optional
code block is given, it will be passed the opened file as an argument, and the
File object will automatically be closed when the block terminates. In this
instance, File.open returns the value of the block.
See IO.new for a list of values for the opt parameter.
誰でもこれを修正する方法について何か考えがありますか?
私が実行しているプログラムは次のとおりです。
filename = ARGV.first
prompt = '> '
txt = File.open(filename)
puts"Here's your file: #{filename}"
puts txt.read()
puts "I'll also ask you to type it again:"
print prompt
file_again = STDIN.gets.chomp()
txt_again = File.open(file_again)
puts txt_again.read()
ARGV.first がテキスト ファイルに設定されている (具体的には、私にとっては ex15_sample.txt )