[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Q: IO.read() and IO.write

Yukihiro Matsumoto

9/17/2008 2:56:00 AM

Hi,

In message "Re: Q: IO.read() and IO.write()"
on Mon, 15 Sep 2008 13:17:56 +0900, kwatch <kwatch@gmail.com> writes:

|I have questions about IO and File class.
|
|* Why is IO.read(filename) defined?
| IMO, File.read() is more natural than IO.read() because
| IO class is not related to filename, I think.

No big reason. Historically IO works on files, i.e. IO.open(path),
so that it was natural to provide these methods in IO too.

|* Is there any reason that IO.write() (or File.write()) is not
|provided?
| I have to define File.write() for each project...
| It is easy to define File.write() but I hope it is provided by Ruby.

For File.read(), when you want to specify file mode, you can just say:

File.read(path, "rb")

For File.write(), it is more likely to be:

File.write(path, str, "wb")

which makes me feel weird. In 1.9, we can write

File.write(path, str, mode: "wb")

which I feel slightly better.


matz.

2 Answers

acmeinc

10/11/2007 12:22:00 PM

0


"Arthur" <arthur2929@shaw.com> wrote in message
news:MPG.2177d22cff92ef49989961@nntp.aioe.org...
> Clay Northwood <Northwood@Northwood.com> wrote:
>> Come on, fess up. You were in a rehab institution recovering from drug
>> abuse.
>>
> More mentally ill babble from the raving anti-semite, racist and
> hypocritical
> sociopathic alcoholic. You may has well just admit to everyone in every
> post
> that you're a jobless socialist attention whore. Nothing but a mental
> case.
Originally, in the context of
the United States, it referred to a
right-wing movement of former political leftists. As Michael Lind has
observed, "Most neoconservative defense intellectuals have their roots on"
.... Voice or no voice, the people can always be brought to the bidding of
the leaders. That is easy. All you have to do is tell them they are being
attacked, and denounce the pacifists for lack of patriotism, and exposing
the country to greater danger." - Herman Goering at the Nuremberg trials

The Zionist Organization of America is a tax-exempt organization under
section 501(c)(3) of the Internal Revenue Code ("IRC") and all contributions
to it are deductible as charitable contributions as provided in IRC section
170. from zoa.org.
Look up "mordechai levy" and his "jdo" to learn more about what some Jews
are doing in this country. See ihr.org/levy.shtml
See ziopedia.org for more facts and logic about zionism.

" ... True, Judaism does not assign the same status to the unborn child as
to life after birth. Thus abortion is always permissible, indeed mandatory,
when the mother's life is threatened. ..." National Review, 7/8/1991. Don
Feder. Also see J J Goldberg's "Jewish Power", pp. 41-42.

" ... 10. The United States was anxious to have other countries supply
assistance to Iraq. For example, in 1984, the Israelis concluded that
Iran was more dangerous than Iraq to Israel's existence due to the growing
Iranian influence and presence in Lebanon. The Israelis approached the
United States in a meeting in Jerusalem that I attended with Donald
Rumsfeld. Israeli Foreign Minister Yitzhak Shamir asked Rumsfeld if the
United States would deliver a secret offer of Israeli assistance to Iraq.
The United States agreed. I travelled wtih Rumsfeld to Baghdad and was
present at the meeting in which Rumsfeld told Iraqi Foreign Minister Tariq
Aziz about Israel's offer of assistance. Aziz refused even to accept the
Israelis' letter to Hussein offering assistance, because Aziz told us that
he would be executed on the spot by Hussein if he did so. ..." from "teicher
+article1413.htm"

the left, not the right. They are products of the influential
Jewish-American sector of the Trotskyist movement of the 1930s and 1940s,
which morphed into anti-communist liberalism between the 1950s and 1970s and
finally into a kind of militaristic and imperial right with no precedents in
American culture or political history." from
disinfopedia.org/wiki.phtml?title=Neoconservative
Then search "global stragety councils". Follow that with "irving kristol
+marxism".
Look up informationclearinghouse.info - article5010.htm.



kwatch

9/17/2008 3:59:00 PM

0

Thank you, Matz.

2008/09/17 Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
> |* Why is IO.read(filename) defined?
> | IMO, File.read() is more natural than IO.read() because
> | IO class is not related to filename, I think.
>
> No big reason. Historically IO works on files, i.e. IO.open(path),
> so that it was natural to provide these methods in IO too.

File.open() is different from IO.open().
IO.open(fd) takes file descriptor as argument,
while File.open(filename) takes filename.

irb(main):012:0> File.open('/tmp/hoge.txt') {|f| f.read }
=> "foo"
irb(main):013:0> IO.open('/tmp/hoge.txt') {|f| f.read }
TypeError: can't convert String into Integer
from (irb):13:in `initialize'
from (irb):13:in `open'
from (irb):13

IO.open() can't take filename as argument, so it is odd for me
that IO.read() is defined in IO class, not File class.


>
> |* Is there any reason that IO.write() (or File.write()) is not
> |provided?
> | I have to define File.write() for each project...
> | It is easy to define File.write() but I hope it is provided by Ruby.
>
> For File.read(), when you want to specify file mode, you can just say:
>
> File.read(path, "rb")

Ruby's manual says that 2nd argument of File.read() is length to read.

irb(main):016:0> File.read('/tmp/hoge.txt')
=> "foo"
irb(main):017:0> File.read('/tmp/hoge.txt', 2)
=> "fo"
irb(main):018:0> File.read('/tmp/hoge.txt', 'rb') # ERROR!
TypeError: can't convert String into Integer
from (irb):17:in `read'
from (irb):17

>
> For File.write(), it is more likely to be:
>
> File.write(path, str, "wb")
>
> which makes me feel weird. In 1.9, we can write
>
> File.write(path, str, mode: "wb")
>
> which I feel slightly better.
> matz.

You mean that there is no plan to add File.write() in Ruby 1.9?

--
regards,
makoto kuwata