Forum: Ruby Pickaxe tutorial section missing info on writing to files

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg Gibson (Guest)
on 2005-11-24 05:08
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
damphyr (Guest)
on 2005-11-24 11:34
(Received via mailing list)
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
http://www.ruby-doc.org/core/
It's really very, very simple.
V.-
--
http://www.braveworld.net/riva
gregory.t.brown (Guest)
on 2005-11-24 18:22
(Received via mailing list)
On 11/24/05, Damphyr <removed_email_address@domain.invalid> 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?
James G. (Guest)
on 2005-11-24 18:26
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
damphyr (Guest)
on 2005-11-24 18:39
(Received via mailing list)
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
gregory.t.brown (Guest)
on 2005-11-24 19:07
(Received via mailing list)
On 11/24/05, Damphyr <removed_email_address@domain.invalid> 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 :)
james_b (Guest)
on 2005-11-24 19:27
(Received via mailing list)
Gregory B. wrote:
>
> Of course, I've already recommended W(p)GtR, so anything else would be
> appreciated :)

WTF[W(p)GtR] ?

James


--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - 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
gregory.t.brown (Guest)
on 2005-11-24 19:31
(Received via mailing list)
On 11/24/05, James B. <removed_email_address@domain.invalid> wrote:
> Gregory B. wrote:
> >
> > Of course, I've already recommended W(p)GtR, so anything else would be
> > appreciated :)
>
> WTF[W(p)GtR] ?

Why's (Poignant) Guide to Ruby
http://www.poignantguide.net/ruby/i/graph-1.gif

Way more fun than Head Trauma!
gregory.t.brown (Guest)
on 2005-11-24 19:31
(Received via mailing list)
On 11/24/05, James B. <removed_email_address@domain.invalid> wrote:

Did you ever find out WTF the 'Little Ruby Book' was? ;)
james_b (Guest)
on 2005-11-24 19:51
(Received via mailing list)
Gregory B. wrote:
> On 11/24/05, James B. <removed_email_address@domain.invalid> wrote:
>
> Did you ever find out WTF the 'Little Ruby Book' was? ;)

Yes, thanks.



James


--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - 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
gregory.t.brown (Guest)
on 2005-11-24 20:07
(Received via mailing list)
On 11/24/05, James B. <removed_email_address@domain.invalid> wrote:
> Gregory B. wrote:
> > On 11/24/05, James B. <removed_email_address@domain.invalid> wrote:
> >
> > Did you ever find out WTF the 'Little Ruby Book' was? ;)
>
> 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?
james_b (Guest)
on 2005-11-24 21:40
(Received via mailing list)
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
http://www.artima.com/rubycs/ - 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
This topic is locked and can not be replied to.