use*_*702 0 ruby arrays map string-substitution
我有一个看起来像这样的二维数组:
[true,false,false]
[false,true,false]
[false,false,true]
Run Code Online (Sandbox Code Playgroud)
我希望我能代替所有的真(布尔)与值"真"(串)和所有的假与"假"
是,请按以下方式使用Array#map:
a = [[true,false,false], [false,true,false], [false,false,true]]
# you can also assign this to a new local variable instead of a,
# if you need to use your source array object in future anywhere.
a = a.map { |e| e.map(&:to_s) }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |