# Block as method argument (Ruby 1.9)

**URL:** <https://www.ruby-forum.com/t/block-as-method-argument-ruby-1-9/207631>\
**Category:** Ruby\
**Created:** [May 30, 2011, 3:16pm UTC](https://www.ruby-forum.com/t/block-as-method-argument-ruby-1-9/207631 "2011-05-30T15:16:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 30, 2011, 3:16pm UTC](https://www.ruby-forum.com/t/block-as-method-argument-ruby-1-9/207631/1 "2011-05-30T15:16:47Z")

</div>

Hi,

can anybody explain while the following code aborts with an error

irb(main):186:0\> print ((1…10).collect do |x| x**2 end)  
SyntaxError: (irb):186: syntax error, unexpected keyword\_do\_block,  
expecting ‘)’  
print ((1…10).collect do |x| x**2 end)  
^  
(irb):186: syntax error, unexpected keyword\_end, expecting $end  
print ((1…10).collect do |x| x\*\*2 end)  
^  
from /usr/bin/irb:12:in `’

whereas following code works as expectd ?

irb(main):187:0\> print ((1…10).collect { |x| x\*\*2 })  
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]=\> nil

I did thought curly-braces “{ }” are equivalent to “do end” when block  
is defined.

I know I can “fix” the first call by omitting a space between print  
method and the first parenthesis, but I’m interested in an explanation  
_why_ .

Thx in an advance.

David
