InQusitive InQusitive - 11 days ago 5
Ruby Question

How do I pass block with other arugments?

def test(args,&block)
yield
end

test 1, {puts "hello"}


last line doesn't work. How do I pass block with other arguments?

Answer
test(1){ puts "hello" }

or

test(1) do 
   puts "hello" 
end

or

blk = proc{ puts "hello" }
test(1, &blk)

You can check out this https://pine.fm/LearnToProgram/chap_10.html

Comments