[ruby-talk:00374] Re: Store and load

From: Akira Endo <akendo@...3.rim.or.jp>
Date: 1999-06-03 03:05:58 UTC
List: ruby-talk #374
Hi, Michael.

In [ruby-talk:00372] Store and load
"Michael Neumann" <neumann@s-direktnet.de> wrote:

> In class IO is the operator << defined, which calls the method "to_s" and send this string to a file or an other device.
> My idea is to do the same for reading. So a method "load" should be defined in class Object and ">>" in IO.

"to_s" can be implemented arbitrarily.  It can return only "" if
you wish.  Scanning back the string to the object is more complicated.
Using Marshal#dump and Marshal#load, you'll be able to define ">>",
but it might be too limited to be useful.
To wait for matz to include IO.scanf might be another solution.

Happy rubying,
Akira

In This Thread