是否有可能像在 Python 中一样,仅在一行中从循环中创建一个数组?我可以将以下代码写成一行吗?
foo = []
bars.each do |bar| foo.append(bar.some_rel) end
最佳答案
关于ruby - 从一行中的循环创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625685/
标签 ruby
是否有可能像在 Python 中一样,仅在一行中从循环中创建一个数组?我可以将以下代码写成一行吗?
foo = []
bars.each do |bar| foo.append(bar.some_rel) end
最佳答案
关于ruby - 从一行中的循环创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625685/
相关文章:
ruby - RSpec:将 `receive ... exactly ... with ... and_return ...` 与不同的 `with` 参数一起使用
ruby-on-rails - Ruby:比较两个数组是否匹配,并按 DESC 顺序对结果进行排序
json - Visual Studio Code (Ruby) 未捕获的异常 - 无法加载此类文件
ruby-on-rails - ActiveRecord 'no method found' 简单一对多关系异常
ruby - 不转义双引号等可打印字符的 Ruby String.dump 替代品 (Ruby 1.8.7)
ruby 风格 : should initialize take a file with data or just the raw data as parameters
ruby-on-rails - 在 Rails 中使用数组解析 JSON