ruby - 将简单的 Ruby 脚本及其输出保存在一个文件中
问题描述
我想将简单的 Ruby 脚本及其输出保存在一个文件中。我知道 jupyter-notebook 是一个很好的工具。Ruby 脚本可以通过使用 iruby 来使用 jupyter 执行。但我不想使用 iruby。因为 iruby 不稳定,而 jupyter 对我来说是过度设计的。
所以我正在寻找一种简单的方法。
你好.rb
puts "hello world"
2 + 3
执行一些不错的命令
irbliketool hello.rb > output.txt
output.txt 看起来像这样...
irb > puts "hello world"
hello world
=> nil
irb > 2+3
=> 5
有好的想法吗?
解决方案
您可以将文件传递给irb
.
irb hello.rb > output.txt
输出不完全相同,但您也可以这样做:
cat hello.rb | irb > out.txt
推荐阅读
- shacl - 如何使用 SHACL 检查多个类实例
- google-cloud-platform - 服务帐户如何在 gcloud 中进行身份验证而不更改环境中的默认 gcloud 帐户?
- python - Kivy image not loading from source
- c++ - 如何在不使用命名空间 chrono 的情况下初始化 std::chrono::duration 常量?
- c# - The connection was not closed when I use using
- ios - IRLDocument Scanner Page Snap cameraview 关闭不会返回到当前的 VC Swift XCode
- python - 在 psycopg2 中为 PostgreSQL 查询使用多个游标有什么好处?
- nlp - PyTorch conv1D 如何处理可变长度序列的填充?
- c# - 使用 IIS 时出现多个错误
- excel - 根据另一个单元格中的条件将正数值单元格输入更改为同一单元格中的负数值