Pickaxe tutorial section missing info on writing to files

Discussion in 'Ruby' started by Greg Gibson, Nov 24, 2005.

  1. Greg Gibson

    Greg Gibson Guest

    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

    --
    Posted via http://www.ruby-forum.com/.
     
    Greg Gibson, Nov 24, 2005
    #1
    1. Advertising

  2. Greg Gibson

    Damphyr Guest

    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

    ____________________________________________________________________
    http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
    http://www.freemail.gr - free email service for the Greek-speaking.
     
    Damphyr, Nov 24, 2005
    #2
    1. Advertising

  3. On 11/24/05, Damphyr <> 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 Brown, Nov 24, 2005
    #3
  4. Greg Gibson

    James Gray Guest

    Re: Pickaxe tutorial section missing info on writing to file

    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 Gray II

    --
    Posted via http://www.ruby-forum.com/.
     
    James Gray, Nov 24, 2005
    #4
  5. Greg Gibson

    Damphyr Guest

    Gregory Brown wrote:
    > On 11/24/05, Damphyr <> 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?

    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

    ____________________________________________________________________
    http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
    http://www.freemail.gr - free email service for the Greek-speaking.
     
    Damphyr, Nov 24, 2005
    #5
  6. On 11/24/05, Damphyr <> wrote:
    > Gregory Brown 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.=20
    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 :)
     
    Gregory Brown, Nov 24, 2005
    #6
  7. Greg Gibson

    James Britt Guest

    James Britt, Nov 24, 2005
    #7
  8. On 11/24/05, James Britt <> wrote:
    > Gregory Brown 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 Brown, Nov 24, 2005
    #8
  9. On 11/24/05, James Britt <> wrote:

    Did you ever find out WTF the 'Little Ruby Book' was? ;)
     
    Gregory Brown, Nov 24, 2005
    #9
  10. Greg Gibson

    James Britt Guest

    James Britt, Nov 24, 2005
    #10
  11. On 11/24/05, James Britt <> wrote:
    > Gregory Brown wrote:
    > > On 11/24/05, James Britt <> 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?
     
    Gregory Brown, Nov 24, 2005
    #11
  12. Greg Gibson

    James Britt Guest

    Gregory Brown wrote:
    > On 11/24/05, James Britt <> wrote:
    >
    >>Gregory Brown wrote:
    >>
    >>>On 11/24/05, James Britt <> 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?
    >


    Oh, sorry. "Little Ruby" is, apparently, shorthand for "A Little Ruby,
    a Lot of Objects", by Brian Marick.


    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
     
    James Britt, Nov 24, 2005
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephane ACOUNIS

    Tutorial on writing testbench files

    Stephane ACOUNIS, Jan 21, 2004, in forum: VHDL
    Replies:
    7
    Views:
    15,940
    QuestaTechnologies
    Apr 20, 2010
  2. Andy Emmerson via .NET 247

    Writing a custom section handler for browserCaps

    Andy Emmerson via .NET 247, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    382
    John Saunders
    Jun 11, 2004
  3. Porky Pig Jr
    Replies:
    5
    Views:
    425
    Porky Pig Jr
    May 3, 2004
  4. David Stockwell
    Replies:
    3
    Views:
    394
    Peter Otten
    May 13, 2004
  5. kampy
    Replies:
    9
    Views:
    336
    Steven D'Aprano
    Oct 19, 2012
Loading...

Share This Page