Ruby:隐式块迭代器
有办法做到这一点吗? 而不是:
links.each do |link|
link.color "red"
end
使迭代器(在 | | 之间)隐式,如下所示:
links.each do
color "red"
end
Is there a way to do this?
instead of:
links.each do |link|
link.color "red"
end
make the iterator (between | |) implicit like so:
links.each do
color "red"
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定这是不可能的。但是,您可以 instance_eval 每个元素,但如果没有充分的理由,我当然不会推荐它
I am pretty sure that this is not possible. You can however instance_eval each element, but I certainly wouldn't recommend it without good reason
我不确定在这种情况下这是否值得付出努力(并且它增加了不必要的复杂性),但很高兴知道您可以执行以下操作:
I'm not sure this is worth the effort in this instance (and it adds unnecessary complexity) but it's nice to know that you can do something like the following: