# Can anyone give a an example of this please

**URL:** <https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145>\
**Category:** Ruby\
**Created:** [October 7, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145 "2010-10-07T14:01:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/1 "2010-10-07T14:01:07Z")

</div>

“code blocks may accept none, one, or more parameters”

I understand how ONE parameter is passed using the ‘each’ method.  
I also understand how TWO parameters is passed, like in this code  
x = { “a” =\> 100, “b” =\> 20 }  
x.delete\_if { |key, value| value \< 25 }  
p x

Can anyone give me a very simple and executable code where:  
NO parameters is passed, and  
THREE parameters is passed

SIMPLE CODE/SYNTAX ONLY PLEASE, BEGINNER HERE. =D

Thanks so much.

---

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:14pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/2 "2010-10-07T14:14:38Z")

</div>

On Thu, Oct 7, 2010 at 2:01 PM, Kaye Ng [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “code blocks may accept none, one, or more parameters”
> 
> I understand how ONE parameter is passed using the ‘each’ method.  
> I also understand how TWO parameters is passed, like in this code  
> x = { “a” =\> 100, “b” =\> 20 }  
> x.delete\_if { |key, value| value \< 25 }  
> p x
> 
> Can anyone give me a very simple and executable code where:  
> NO parameters is passed, and

irb(main):001:0\> [0,1,2,3].each { puts “no param” }  
no param  
no param  
no param  
no param  
=\> [0, 1, 2, 3]

> THREE parameters is passed

irb(main):002:0\> [[ 1,2,3] ].each { |i,j,k| puts i+j+k }  
6  
=\> [[1, 2, 3]]

Ruby version is 1.9.1

> SIMPLE CODE/SYNTAX ONLY PLEASE, BEGINNER HERE. =D

Was this simple enough? 🙂

–  
Phillip G.

Though the folk I have met,  
(Ah, how soon!) they forget  
When I’ve moved on to some other place,  
There may be one or two,  
When I’ve played and passed through,  
Who’ll remember my song or my face.

---

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/3 "2010-10-07T14:21:40Z")

</div>

On Thu, Oct 7, 2010 at 2:01 PM, Kaye Ng [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> THREE parameters is passed  
> 14:14:24 ~$ ruby19 \<\<CODE  
> def none; yield; end  
> def one; yield 1; end  
> def three; yield 1,2,3; end  
> none { puts “called” }  
> one {|x| puts “Got one: #{x}”}  
> three {|a,b,c| puts “Got three: #{a}, #{b}, #{c}”}  
> three {|a| p a}  
> three {|\*a| p a}  
> CODE  
> called  
> Got one: 1  
> Got three: 1, 2, 3  
> 1  
> [1, 2, 3]  
> 14:15:44 ~$

> SIMPLE CODE/SYNTAX ONLY PLEASE, BEGINNER HERE. =D

Please do not shout.

robert

---

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/4 "2010-10-07T14:24:01Z")

</div>

On Thu, Oct 7, 2010 at 2:14 PM, Phillip G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > NO parameters is passed, and
> 
> irb(main):001:0\> [0,1,2,3].each { puts “no param” }  
> no param  
> no param  
> no param  
> no param  
> =\> [0, 1, 2, 3]

There is _one_ parameter passed - you just do not pick it up in the  
block.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:39pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/5 "2010-10-07T14:39:49Z")

</div>

On Thu, Oct 7, 2010 at 2:17 PM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > irb(main):001:0\> [0,1,2,3].each { puts “no param” }  
> > no param  
> > no param  
> > no param  
> > no param  
> > =\> [0, 1, 2, 3]
> 
> There is _one_ parameter passed - you just do not pick it up in the block.

Ah, then I misunderstood the question, I guess, thinking that the OP  
wanted an example of a block without a parameter enclosed in ||,  
analogus to the |key,value| pair in the OP’s example.

Though, do you count the array index passed into the #each block as a  
parameter, or not?

–  
Phillip G.

Though the folk I have met,  
(Ah, how soon!) they forget  
When I’ve moved on to some other place,  
There may be one or two,  
When I’ve played and passed through,  
Who’ll remember my song or my face.

---

<div class="post-metadata">

**Author:** ![marlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@marlon](https://www.ruby-forum.com/u/marlon)\
**Post date:** [October 7, 2010, 2:49pm UTC](https://www.ruby-forum.com/t/can-anyone-give-a-an-example-of-this-please/196145/6 "2010-10-07T14:49:11Z")

</div>

On Thu, Oct 7, 2010 at 2:29 PM, Phillip G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ah, then I misunderstood the question, I guess, thinking that the OP  
> wanted an example of a block without a parameter enclosed in ||,  
> analogus to the |key,value| pair in the OP’s example.

Actually I am not sure what the OP _really_ wanted either. 🙂 I just  
wanted to point out that the parameter is actually passed (which you  
can see if you add a formal parameter to the block) but that the block  
does not use it.

> Though, do you count the array index passed into the #each block as a  
> parameter, or not?

The index is only passed with #each\_index. And yes, of course it is a  
parameter.

Kind regards

robert
