rails - Redirecting console output to a file

前端 未结 7 844
时光取名叫无心
时光取名叫无心 2020-12-12 09:51

On a bash console, if I do this:

cd mydir
ls -l > mydir.txt

The > operator captures the standard input and redirects it to a file; so I

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 10:28

    A quick one-off solution:

    irb:001> f = File.new('statements.xml', 'w')
    irb:002> f << Account.find(1).statements.to_xml
    irb:003> f.close
    

    Create a JSON fixture:

    irb:004> f = File.new(Rails.root + 'spec/fixtures/qbo/amy_cust.json', 'w')
    irb:005> f << JSON.pretty_generate((q.get :customer, 1).as_json)
    irb:006> f.close
    

提交回复
热议问题