# What does the ' & ' mean when associated to a block?

**URL:** <https://www.ruby-forum.com/t/what-does-the-mean-when-associated-to-a-block/126681>\
**Category:** Rails\
**Created:** [January 21, 2008, 11:04am UTC](https://www.ruby-forum.com/t/what-does-the-mean-when-associated-to-a-block/126681 "2008-01-21T11:04:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [January 21, 2008, 11:04am UTC](https://www.ruby-forum.com/t/what-does-the-mean-when-associated-to-a-block/126681/1 "2008-01-21T11:04:38Z")

</div>

I have a function that is defined as such:

def rubyfunc( &block )  
…  
end

Its called by “interface.rubyfunc” (Where obviously interface is a  
class)

Can anyone give me an explanation of what the “&”-sign is and in general  
what the parameter is when I call it from an empty function?

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [January 21, 2008, 11:32am UTC](https://www.ruby-forum.com/t/what-does-the-mean-when-associated-to-a-block/126681/2 "2008-01-21T11:32:07Z")

</div>

the syntax of ‘&’ comes from the c/c++ lang and means that the variable  
‘block’ is not a parameter in the normal list.

‘block’ would take a ruby variable

while ‘&block’ takes a block of code

The function would be called like this

rubyfunc do |some\_param|  
puts param.to\_s  
end

where the do/end is becomes a Proc object and gets stored in the &block  
arg

& must be used on the last argument in the function definition.

An instance of a Proc object can be executed via \<var\_name\>.call()

note that the do/end can be substituted with {} but should only be used  
on single line blocks ie.

rubyfunc{ puts ‘hello’ }

-K

p.s. this is a ruby syntax question and should be posted on the ruby  
forum in the future.
