Pickaxe tutorial section missing info on writing to files

The Pickaxe seems to be missing an example (or two) about how to write a
file in Ruby (pgs 23 and 131) so I used the PLEAC. I have now been
forbidden, by my friend, Greg Brown, from learning Ruby using Perl
conventions.

Thanks,

Greg Gibson

Greg Gibson wrote:

The Pickaxe seems to be missing an example (or two) about how to write a
file in Ruby (pgs 23 and 131) so I used the PLEAC. I have now been
forbidden, by my friend, Greg Brown, from learning Ruby using Perl
conventions.

You mean

File.open(“test.txt”,“w”){|f|
f<<“Writing lot’s of stuff to file”
}

?
Check IO and File in the Reference of the Pickaxe or
RDoc Documentation
It’s really very, very simple.
V.-

http://www.braveworld.net/riva

On 11/24/05, Damphyr [email protected] wrote:

You mean

File.open(“test.txt”,“w”){|f|
f<<“Writing lot’s of stuff to file”
}

He did figure it out… by reading PLEAC.

But don’t you think in the two sections of the pickaxe about ‘writing’
this simple line should have been shown?

Gregory B. wrote:

He did figure it out… by reading PLEAC.

But don’t you think in the two sections of the pickaxe about ‘writing’
this simple line should have been shown?
Don’t know. I was going to say “Since Pickaxe includes the core
Reference, this is technically documented” but then I looked at the
aforementioned Pickaxe and the above three lines of code seem to be
spread over 5 pages of Pickaxe (v2, p128-132) text, while ::File has no
such example :).

It’s actually the second time I see someone asking this question. The
first time I was taken aback, so that I didn’t even ask if he meant the
obvious :).
That it is obvious is for me a sign that I’m too deep into Ruby and have
forgotten the bad old days :). Oh happiness!
Cheers,
V.-

http://www.braveworld.net/riva

damphyr wrote:

You mean

File.open(“test.txt”,“w”){|f|
f<<“Writing lot’s of stuff to file”
}

Using puts is probably easier, for line oriented data:

File.open(“data.txt”, “w”) do |file|
file.puts “Line of date here.”
file.puts “Another line.”
end

Hope that helps.

James Edward G. II

On 11/24/05, Damphyr [email protected] wrote:

Gregory B. wrote:

But don’t you think in the two sections of the pickaxe about ‘writing’
this simple line should have been shown?
Don’t know. I was going to say “Since Pickaxe includes the core
Reference, this is technically documented” but then I looked at the
aforementioned Pickaxe and the above three lines of code seem to be
spread over 5 pages of Pickaxe (v2, p128-132) text, while ::File has no
such example :).

I think the Pickaxe is wonderful… in combination with some other
tutorials and in the company of a good friend, it’ll help you start
writing ruby very quickly.

I didn’t notice this issue when I was learning, because I probably
googled how to do File I/O or I fired off an email to James Edward
Gray II (this was before I knew about this wonderful list). I think
this is common practice for experienced programmers, to ask one of
their buddies that they know has skill in a certain area, or to google
for an answer, or hit the API references and dig right in, but for
someone who hasn’t actively coded in a while or comes from a totally
different language conceptually (I came from perl, so it wasn’t a
terrible ride, but I believe Mr. Gibson comes from C ), the Pickaxe
alone might be a bit misleading as it trys to be a tutorial, but
misses out on what are very simple but common concerns.

Maybe in the 3rd edition the tutorial section will be more complete.
It’s enormously difficult to put so many concepts in one book, and
they did a great job on most accounts.

Does anyone know a good book for people who grasp programming concepts
but really have no ruby experience whatsover (and possibly little
experience with OO). I am in the position where I am teaching
several people who fit this category and would like to be able to
recommend a book that is up to date with 1.8.x that will be a more
gentle entry into the language.

Of course, I’ve already recommended W(p)GtR, so anything else would be
appreciated :slight_smile:

Gregory B. wrote:

Of course, I’ve already recommended W(p)GtR, so anything else would be
appreciated :slight_smile:

WTF[W(p)GtR] ?

James

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

On 11/24/05, James B. [email protected] wrote:

Did you ever find out WTF the ‘Little Ruby Book’ was? :wink:

Gregory B. wrote:

On 11/24/05, James B. [email protected] wrote:

Did you ever find out WTF the ‘Little Ruby Book’ was? :wink:

Yes, thanks.

James

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

On 11/24/05, James B. [email protected] wrote:

Gregory B. wrote:

Of course, I’ve already recommended W(p)GtR, so anything else would be
appreciated :slight_smile:

WTF[W(p)GtR] ?

Why’s (Poignant) Guide to Ruby

Way more fun than Head Trauma!

On 11/24/05, James B. [email protected] wrote:

Gregory B. wrote:

On 11/24/05, James B. [email protected] wrote:

Did you ever find out WTF the ‘Little Ruby Book’ was? :wink:

Yes, thanks.

Actually, that was a question on another thread that you asked about
that I don’t believe the OP responded to. What is the Little Ruby
Book, is that another reference to Why’s Guide? Or something else?

Gregory B. wrote:

Actually, that was a question on another thread that you asked about
that I don’t believe the OP responded to. What is the Little Ruby
Book, is that another reference to Why’s Guide? Or something else?

Oh, sorry. “Little Ruby” is, apparently, shorthand for “A Little Ruby,
a Lot of Objects”, by Brian M…

http://visibleworkings.com/little-ruby/

quote:

This is a draft book titled A Little Ruby, A Lot of Objects. It’s in the
style of Friedman and Felleisen’s wonderful The Little Lisper (now
called The Little Schemer), but on a different topic. From the preface:

 Welcome to my little book. In it, my goal is to teach you a way to

think about computation, to show you how far you can take a simple idea:
that all computation consists of sending messages to objects.
Object-oriented programming is no longer unusual, but taking it to the
extreme - making everything an object - is still supported by only a few
programming languages.

 Can I justify this book in practical terms? Will reading it make

you a better programmer, even if you never use “call with current
continuation” or indulge in “metaclass hackery”? I think it might, but
perhaps only if you’re the sort of person who would read this sort of
book even if it had no practical value.

 The real reason for reading this book is that the ideas in it are

neat. There’s an intellectual heritage here, a history of people
building idea upon idea. It’s an academic heritage, but not in the fussy
sense. It’s more a joyous heritage of tinkerers, of people buttonholing
their friends and saying, “You know, if I take that and think about it
like this, look what I can do!”

:etouq

James

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools