I am getting below error when executing code:
example.rb:9:in `<main>': undefined method `each' for main:Object (NoMethodError)
Line 9 is second last line in my code.
My code:
class TargetProvider
def each(target,&block)
block.call(target)
end
end
tp = TargetProvider.new
each { puts "Hello!" }
tp.each(1, each)
My motive is to call block with target parameter.
How can I pass a block outside class. Any help please.