Converting Ruby's Yield Inside Of Nested Functions Into Node.js
I'm trying to convert a chunk of Ruby code into Node.js. One particular piece has me stumped, concerning yield. The code goes like this: each_pair(hash['args'][0]) do |key, value,
Solution 1:
No, that's an OK translation. It's a little deceptive because any method in ruby can be called with an implicit block. If it's there, you can yield
it. It's one of those shorthand tricks that you forget if you don't use them for a while :)
In the ruby version, you could also add a &block
argument and replace yield(...
with block.call(...
. It'd be functionally equivalent.
Post a Comment for "Converting Ruby's Yield Inside Of Nested Functions Into Node.js"