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
Sharma C. wrote:
endless_string_succession(‘aa’) { |x| puts x }
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 C. [email protected] wrote:
Any ideas?
Thanks In advance,
Sharma
–
Posted via http://www.ruby-forum.com/.
–
http://www.jeremymcanally.com/
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/
My blogs:
http://www.rubyinpractice.com/
On Fri, 2007-02-23 at 15:31 +0900, Sharma C. wrote:
Any ideas?
You forgot to pass the block to the method.
endless_string_succession(‘fsck’) {|str| #some crap }
Thank you guys for your fast && great responses…
Hemant K. wrote:
On Fri, 2007-02-23 at 15:31 +0900, Sharma C. wrote:
Any ideas?
You forgot to pass the block to the method.
endless_string_succession(‘fsck’) {|str| #some crap }