# Proc.new and return

**URL:** <https://rubytalk.org/t/proc-new-and-return/44833>\
**Category:** ruby-talk\
**Created:** [28 February 2008 13:01 UTC](https://rubytalk.org/t/proc-new-and-return/44833 "2008-02-28T13:01:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jari\_Williamsson](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@Jari\_Williamsson](https://rubytalk.org/u/Jari_Williamsson)\
**Post date:** [28 February 2008 13:01 UTC](https://rubytalk.org/t/proc-new-and-return/44833/1 "2008-02-28T13:01:02Z")

</div>

S2 wrote:

> I am sure this is a really easy question for most of you, but i was not able to find an answer to this, or to understand the difference between this two:
> 
> $ irb  
> irb(main):001:0\> a = Proc.new {true}  
> =\> #\<Proc:0xb7cae308@(irb):1\>  
> irb(main):002:0\> b = a.call  
> =\> true  
> irb(main):003:0\> a = Proc.new {return true}  
> =\> #\<Proc:0xb7c9f768@(irb):3\>  
> irb(main):004:0\> b = a.call  
> LocalJumpError: unexpected return  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):3  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4:in `call'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from :0
> 
> why can't a block return something?

The result you're getting is for having a return keyword outside a method. If you instead do this, return will work.

> **···**
>
> ---  
> def my\_proc  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a = Proc.new {return true}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Call it"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.call  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "This will never happen"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;false  
> end
> 
> puts my\_proc  
> ---
> 
> =\>  
> Call it  
> true
> 
> Best regards,
> 
> Jari Williamsson
