Based on Nikita Misharin, answer here: [ / questions / 652246 / in-ruby-can-you-use-the-lambda-or-or-proc-call-method-to-invoke-an-iterator / 2563620 # 2563620 , I like it:
def iterator(x) for i in 1 .. 5 yield x * i end end iteratorWrapper = -> (m,&block) { iterator(m) {|n| block.call n} } iteratorWrapper.call(2) { |y| puts y }
It answers my question here [ In Ruby, can you use the lambda or Proc invocation method to invoke the iterator? .
By wrapping the iterator, it can be arbitrarily passed to other methods and iterating over their blocks.
Mike stitt
source share