From: Ruby Newbee Date: 2010-01-02T19:47:21+09:00 Subject: block.call Hello gurus, please see the code below, why passing a block to a function then call block.call in the function will get success, but run block.call out of a function will get failed? irb(main):023:0* def myhi(&block) irb(main):024:1> block.call irb(main):025:1> end => nil irb(main):026:0> myhi { puts "hi welcome" } hi welcome => nil irb(main):027:0> { puts "hi welcome" }.call SyntaxError: (irb):27: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' { puts "hi welcome" }.call ^ (irb):27: syntax error, unexpected '}', expecting $end { puts "hi welcome" }.call ^ from /usr/bin/irb:12:in `
'