# Ruby 1.9 : What is the use for Proc#yield

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610>\
**Category:** Ruby\
**Created:** [June 24, 2007, 12:12am UTC](https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610 "2007-06-24T00:12:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [June 24, 2007, 12:12am UTC](https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610/1 "2007-06-24T00:12:58Z")

</div>

I’m reading through Mauricio’s list of changes[0] to Ruby 1.9 and  
having trouble with understanding the point of Proc#yield

* * *

Invokes the block, setting the block’s parameters to the values in  
params in the same manner the yield statement does.

```
a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
a_proc.yield([9, 1, 2, 3]) #=> [9, 18, 27]
a_proc = Proc.new {|a,b| a}
a_proc.yield(1,2,3) # => [1]

```

* * *

It seems like this is the same as Proc#[] or Proc#call

> > VERSION  
> > =\> “1.8.4”
> 
> > a\_proc = Proc.new {|a, _b| b.collect {|i| i_a }}  
> > =\> #Proc:0x00317930@:8(irb)
> 
> > a\_proc[9,1,2,3]  
> > =\> [9, 18, 27]
> 
> > a\_proc[[9,1,2,3]]  
> > =\> [9, 18, 27]
> 
> > a\_proc = Proc.new { |a,b| a }  
> > =\> #Proc:0x0030a44c@:11(irb)
> 
> > a\_proc[1,2,3]  
> > =\> 1

Mauricio says “Proc#yield was added (also NilClass#yield which raises  
a LocalJumpError so you can use it on &block).”

The best ‘feature’ I can think of is that this lets you do

def something(&block)  
block.yield(1,2,3)  
rescue LocalJumpError  
puts “was expected a block”  
end

But I’m not sure I’m convinced of how cool that is. Am I missing  
something?

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [June 24, 2007, 12:14am UTC](https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610/2 "2007-06-24T00:14:58Z")

</div>

On 6/23/07, Gregory B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m reading through Mauricio’s list of changes[0] to Ruby 1.9 and  
> having trouble with understanding the point of Proc#yield

whoops, forgot to link.

[0] [eigenclass.org](http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9)

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [June 24, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610/3 "2007-06-24T17:35:18Z")

</div>

On 6/24/07, Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> In message “Re: Ruby 1.9 : What is the use for Proc#yield”  
> on Sun, 24 Jun 2007 07:12:20 +0900, “Gregory B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> |I’m reading through Mauricio’s list of changes[0] to Ruby 1.9 and  
> |having trouble with understanding the point of Proc#yield
> 
> It’s mere alias to call, just to describe the intention to invoke it  
> as a block passed.

Thanks for clarifying this.

-greg

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [June 24, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/ruby-1-9-what-is-the-use-for-proc-yield/107610/4 "2007-06-24T16:53:14Z")

</div>

Hi,

In message “Re: Ruby 1.9 : What is the use for Proc#yield”  
on Sun, 24 Jun 2007 07:12:20 +0900, “Gregory B.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|I’m reading through Mauricio’s list of changes[0] to Ruby 1.9 and  
|having trouble with understanding the point of Proc#yield

It’s mere alias to call, just to describe the intention to invoke it  
as a block passed.

```
          matz.

```
