[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02939] Re: Iterators...

From: "Dat Nguyen" <thucdat@...>
Date: 2000-05-23 03:39:02 UTC
List: ruby-talk #2939


>From: h.fulton@att.net
>Reply-To: ruby-talk@netlab.co.jp
>To: ruby-talk@netlab.co.jp (ruby-talk ML)
>Subject: [ruby-talk:02932] Iterators...
>Date: Mon, 22 May 2000 22:53:11 +0000
>
>I find myself wishing for something that
>may not exist (but perhaps should?).
>
>In an abitrary iterator, I want to know
>whether I am on the first or last iteration.
>For example:
>
>   myarray.each { |x| print "{ " if iter_first?
>     print x
>     if iter_last?
>       print " }\n"
>     else
>       print ", "
>     end
>   }
>
>
>This would print something like:
>
>   { 1, 2, 3, 4, 5 }
>
>OK, it might be fairly easy to fake this for
>arrays, but not hashes and other things...
>
>Comments, anyone?
>
>
>Hal

How about:

sep = "{"
(1..5).each {
	|x|
	print "#{sep} #{x} "
	sep = ","
}
print "}\n"

Dat
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

In This Thread

Prev Next