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

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

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

From: "David Douthitt" <DDouthitt@...>
Date: 2000-05-23 03:04:39 UTC
List: ruby-talk #2937
It almost didn't occur to me, but I do something similar to this for my =
HTML libraries.

Try this code (to replace your example):

Some_class.my_iterator {
   print "{ "
   yield
   print " }"
   }

Some_class.my_iterator {
   [ 1..5 ].each { |x|
      print x, ", "
      }
   }

Of course, that leaves an extra "," hanging out there, but hey it's valid =
Perl code :-)

Brings up an interesting point: the code snippet:

{ 1, 2, 3, }

is valid Perl code; is it valid Ruby code?  If not, why not?

>>> h.fulton@att.net 5/22/00 5:53p >>>
I find myself wishing for something that=20
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=20

In This Thread

Prev Next