小编Kat*_*ryn的帖子

是否有相当于 Ruby 的 shell 脚本的 xtrace 选项?

在调试 shell 脚本时,我发现使用xtraceon运行会很有帮助:

-x    xtrace        Print commands  and  parameter
                    assignments when they are exe-
                    cuted, preceded by  the  value
                    of PS4.
Run Code Online (Sandbox Code Playgroud)

例如:

$ set -x
$ s='Say again?'
+ s='Say again?'

# Other commands that might mess with the value of $s

$ echo $s
+ echo Say 'again?'
Say again?
Run Code Online (Sandbox Code Playgroud)

我知道,Ruby有交互式调试程序,如byebug,但我正在寻找的东西,将很容易打开用于记录自动化脚本。

我确实找到了一个xtrace gem,但它与 PHP 格式有关。

我还看到有一个Tracer 类和一个TracePoint 类,它们似乎提供了一种在执行语句时打印语句的方法。但是我还没有找到任何打印变量值的方法(而不仅仅是变量名):

$ ruby -r tracer trace.rb 
#0:/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:Kernel:<:       return gem_original_require(path) …
Run Code Online (Sandbox Code Playgroud)

ruby

5
推荐指数
1
解决办法
314
查看次数

如何在ruby中合并两个数组对象?

如果我从两个数组开始,例如:

array1 = [{"ID":"1","name":"Dog"}]
array2 = [{"ID":"2","name":"Cat"}]
Run Code Online (Sandbox Code Playgroud)

如何将此数组合并为一个这样的数组?

arraymerge = [{"ID":"1","name":"Dog"}, {"ID":"2","name":"Cat"}]
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

3
推荐指数
2
解决办法
1430
查看次数

标签 统计

ruby ×2

ruby-on-rails ×1