Ruby 哪里有$>;跑了?

Ruby 哪里有$>;跑了?,ruby,predefined-variables,Ruby,Predefined Variables,这是解决问题的方法之一 a=[]$ $>工作正常,问题出在其他地方 irb> $><<:hello_world hello_world=> #<IO:<STDOUT>> 如果您将它放在一个文件中,并使用命令行参数运行它,或者通过管道输入其他参数,那么它可能会实现您所期望的功能 如果用数组替换$ irb> $><<:hello_world hello_world=> #<IO:<STDOUT>&

这是解决问题的方法之一


a=[]$ 
$>
工作正常,问题出在其他地方

irb> $><<:hello_world
hello_world=> #<IO:<STDOUT>>
如果您将它放在一个文件中,并使用命令行参数运行它,或者通过管道输入其他参数,那么它可能会实现您所期望的功能

如果用数组替换
$
irb> $><<:hello_world
hello_world=> #<IO:<STDOUT>>
irb> $<.map { }
# hangs...
arr = ['0', '1', '2']
a=[];arr.map{|l|l=='0'?($><<a.pop):a<<l}
#=> [#<IO:<STDOUT>>, ["1", "2"], ["1", "2"]]