方法的 Ruby 重构
希望将其重构为一行:
def sum_something
sum = 0
self.each { |a| sum += a }
return sum
end
必须有一种方法可以在块内定义“总和”,并且我可以删除“返回”。
Would love to refactor this into just one line:
def sum_something
sum = 0
self.each { |a| sum += a }
return sum
end
There must be a way to define 'sum' within the block and I could drop the 'return'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)