[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

why this program not working ?

Sharma Chelluri

2/23/2007 6:31:00 AM

Hi

I am trying to execute this program from cookbook.

def endless_string_succession(start)
while true
yield start
start = start.succ
end
end

puts endless_string_succession 'aa'

**********************************************
Error messages that I am getting

C:/rubyexmples/1_16.rb:8: warning: parenthesize argument(s) for future
version
C:/rubyexmples/1_16.rb:3:in `endless_string_succession': no block given
(LocalJumpError)
from C:/rubyexmples/1_16.rb:8

Any ideas?

Thanks In advance,
Sharma

--
Posted via http://www.ruby-....

4 Answers

Florian Frank

2/23/2007 6:42:00 AM

0

Sharma Chelluri wrote:
> I am trying to execute this program from cookbook.
>
> def endless_string_succession(start)
> while true
> yield start
> start = start.succ
> end
> end
>
> puts endless_string_succession 'aa'
>
endless_string_succession('aa') { |x| puts x }

--
Florian Frank


Jeremy McAnally

2/23/2007 6:48:00 AM

0

Florian gave you the right solution, but to explain why, he should
have said the 'yield' keyword yields control of the code flow to a
block provided as a parameter (e.g., he provided 'puts x' as the block
parameter).

I suggest reading in the Pickage, Ruby for Rails, my book, or in your
favorite Ruby book about block parameters to understand more.

--Jeremy

On 2/23/07, Sharma Chelluri <rubyrailssharma@yahoo.com> wrote:
> Hi
>
> I am trying to execute this program from cookbook.
>
> def endless_string_succession(start)
> while true
> yield start
> start = start.succ
> end
> end
>
> puts endless_string_succession 'aa'
>
> **********************************************
> Error messages that I am getting
>
> C:/rubyexmples/1_16.rb:8: warning: parenthesize argument(s) for future
> version
> C:/rubyexmples/1_16.rb:3:in `endless_string_succession': no block given
> (LocalJumpError)
> from C:/rubyexmples/1_16.rb:8
>
> Any ideas?
>
> Thanks In advance,
> Sharma
>
> --
> Posted via http://www.ruby-....
>
>


--
http://www.jeremymca...

My free Ruby e-book:
http://www.humblelittlerubybook...

My blogs:
http://www.mrneigh...
http://www.rubyinpra...

hemant

2/23/2007 6:48:00 AM

0

On Fri, 2007-02-23 at 15:31 +0900, Sharma Chelluri wrote:
> Hi
>
> I am trying to execute this program from cookbook.
>
> def endless_string_succession(start)
> while true
> yield start
> start = start.succ
> end
> end
>
> puts endless_string_succession 'aa'
>
> **********************************************
> Error messages that I am getting
>
> C:/rubyexmples/1_16.rb:8: warning: parenthesize argument(s) for future
> version
> C:/rubyexmples/1_16.rb:3:in `endless_string_succession': no block given
> (LocalJumpError)
> from C:/rubyexmples/1_16.rb:8
>
> Any ideas?

You forgot to pass the block to the method.

endless_string_succession('fsck') {|str| #some crap }






Sharma Chelluri

2/23/2007 9:29:00 AM

0

Thank you guys for your fast && great responses..


Hemant Kumar wrote:
> On Fri, 2007-02-23 at 15:31 +0900, Sharma Chelluri wrote:
>>
>>
>> Any ideas?
>
> You forgot to pass the block to the method.
>
> endless_string_succession('fsck') {|str| #some crap }


--
Posted via http://www.ruby-....