Tech Support > Computers & Technology > Programming > Free Ruby eBook
Free Ruby eBook
Posted by Huw Collingbourne on June 17th, 2006



If anyone here is interested in learning Ruby, you may like to take a look
at the free eBook which I have just put online: The Little Book Of Ruby. It
contains ten chapters to cover the fundamentals of Ruby programming plus all
the source code for each example in the text.

You can download the eBook and code from:
http://www.sapphiresteel.com/The-Little-Book-Of-Ruby

best wishes
Huw Collingbourne
================================
Bitwise Magazine
www.bitwisemag.com
Dark Neon Ltd.
================================


Posted by Richard Heathfield on June 17th, 2006


Huw Collingbourne said:

Thank you, Huw. I took a quick look.

I must take issue with you on one point you raise early in your ebook: "The
simplest way to get Ruby installed on a PC is by using the Ruby Installer
for Windows". I beg to differ. The simplest way to get Ruby installed on a
PC is to be running a decent Linux distro, in which case you don't have to
bother because it's already been done for you.

Oh, just one other minor nit - your Ruby program files don't end in newline
characters. No big deal, just looks a little odd when you do this:

me@here:~/dev/ruby/littlebook/one> cat helloworld.rb
# Ruby Sample program from www.sapphiresteel.com / www.bitwisemag.com

puts 'Hello world'me@here:~/dev/ruby/littlebook/one>

Trivially fixable, of course, but you might want to hack the program files
and re-zip them, perhaps maybe.

I got through about 17 pages just now, learning Ruby and looking for nits to
pick at the same time, and I have to say I couldn't find any of the little
tykes - not a single one.

So this looks like a good job well done.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Huw Collingbourne on June 17th, 2006


"Richard Heathfield" <invalid@invalid.invalid> wrote

Ah, you spotted my prejudice! ;-)

You are, I'm sure, quite correct - however, as I am currently involved in
the development of a Visual Studio IDE for Ruby, I confess to being somewhat
Windows-centric. I'll try to correct my assumptions in time for the 2nd
edition, though....

They end in CR+LF. I hadn't realised that combination caused problems on
Linux. The editors I've tested them with (Visual Studio, SciTE and Komodo)
all load and display the files correctly. Are you saying that each file
needs to end with an additional blank line for use in Linux?

Let's hope they don't spring out at you on page 18 :-)

Many thanks.

best wishes
Huw Collingbourne
================================
Bitwise Magazine
www.bitwisemag.com
Dark Neon Ltd.
================================



Posted by Randy Howard on June 17th, 2006


Richard Heathfield wrote
(in article <Qv6dnflgfPOEkQnZRVnyvg@bt.com>):

I thought you refused to play with pdf files.

[snip]
I'll check it out. Usually if Richard doesn't find flaws in
something almost immediately, it's pretty good. He'd make
people lose a lot of sleep if he was their proofreader.

:-)




--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw






Posted by Richard Heathfield on June 17th, 2006


[This is not a big deal. I think Huw has simply misunderstood a tiny thing
about text files. On the whole his e-book appears to be excellent. We are
just chasing down the tiniest, tiniest nit, that's all.]

Huw Collingbourne said:

Er, no they don't.

me@here:~/dev/ruby/littlebook/one> hd helloworld.rb
23 20 52 75 62 79 20 53 61 6D 70 6C 65 20 70 72
6F 67 72 61 6D 20 66 72 6F 6D 20 77 77 77 2E 73
61 70 70 68 69 72 65 73 74 65 65 6C 2E 63 6F 6D
20 2F 20 77 77 77 2E 62 69 74 77 69 73 65 6D 61
67 2E 63 6F 6D 0D 0A 0D 0A 70 75 74 73 20 27 48
65 6C 6C 6F 20 77 6F 72 6C 64 27
me@here:~/dev/ruby/littlebook/one>

Well, it doesn't. The newline is all that is needed. The carriage return is
generally ignored, but if it does cause problems it can easily be removed
with tr, or with recode (both are command line utilities). (When you
specify ASC mode in FTP, this is the translation you get - CR+LF -> LF if
you're going from Windows to Linux, and LF -> CR+LF if you're going the
other way. (Macs get CR, of course, rather than LF or CR+LF.)

So it's not the CR thing. And indeed the absence of a newline on the last
line doesn't seem to worry Ruby either. The only thing it really messes up
is "cat" (your equivalent is "type", in a console window). I haven't tested
on Windows, though. I'll do so after my kids' bedtime, since I don't want
to interfere with their game.

Try a hex dump.

No, I'm saying it needs to end with a newline in order to be a valid text
file as most people seem to understand the term (i.e. a series of 0 or more
lines, each of which is a series of 0 or more characters terminating in a
newline).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Richard Heathfield on June 17th, 2006


Randy Howard said:

I don't like them, that's for sure. But on the other hand, I *do* like Huw
Collingbourne. He has a brain in there somewhere. Perhaps he can be
persuaded to do a PostScript version.

I'm glad that spelling and grammar aren't treated too seriously on Usenet,
and that crits of them are considered infra dig. Otherwise, I'd never have
any time to get anything /else/ done.

Such as learning Ruby.

Which was NOT on my list, durn it!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Randy Howard on June 17th, 2006


Richard Heathfield wrote
(in article <BoWdnd53m9twxwnZRVny1w@bt.com>):

My mistake, I thought I recalled you being MUCH more ardently
opposed to them.

I read through a bit of it earlier today, then went out and
grabbed all of the latest ruby bits, the gems stuff, ruby on
rails, etc. for the Mac. After a lot of playing around, I'm
only marginally better off than I was when I started, since the
system had a version only 0.0.2 revs 'behind' when I started,
but it was an interesting ride, and I understand the
underpinnings much better as a result.

LOL

I know what you mean. I sniffed around it a while back and it
looked promising, but I fell off into something else and didn't
get back. I have a very long plane trip in front of me though,
so this looks like a good way to pass the time.

Thanks to Mr. Collingbourne for bringing it to my attention
again.



--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw






Posted by Richard Heathfield on June 17th, 2006


Randy Howard said:

Right. And I am. In fact, if it hadn't been Huw, I'd have said "go away and
don't come back until you've learned HTML" or something equally nasty and
bad-tempered. But it /was/ Huw, so I gave him the benefit of the doubt. I
am still hoping he'll provide it in a portable document format instead of
PDF.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Roberto Waltman on June 17th, 2006


Richard Heathfield wrote:
Need to remember that line
No doubt you know this, but for other's benefit: if you'd rather use
Ghostscript than a PDF viewer, it is trivial to convert a PDF file to
postscript by just "printing" to a postscript printer and saving the
output file. (It may be necessary to edit out a couple lines that set
printer modes, etc. )

I occasionally do it when I get a PDF document that uses features
available only in the latest and bloatedest versions of Acrobat
reader: PDF --> postscript --> back to PDF but at a level suitable
for Acrobat versions 3 or 4. (That's for work, were I must use a
Windows OS. At home I am quite happy with xpdf and evince under Linux)


Posted by Russell Shaw on June 18th, 2006


Roberto Waltman wrote:
man pdf2ps

Posted by Richard Heathfield on June 18th, 2006


Russell Shaw said:

me@here:~/dev/ruby> pdf2ps LittleBookOfRuby.pdf
Error: /undefined in --get--
Operand stack:
--dict:7/7(L)-- --dict:9/14(L)-- --dict:9/14(L)-- FormType
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3
%oparray_pop --nostringval-- 2 1 85 --nostringval--
%for_pos_int_continue --nostringval-- --nostringval-- 2 9
%oparray_pop --nostringval-- false 1 %stopped_push
--nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1042/1241(ro)(G)-- --dict:0/20(G)-- --dict:71/200(L)--
--dict:71/200(L)-- --dict:97/127(ro)(G)-- --dict:218/230(ro)(G)--
--dict:19/24(L)-- --dict:4/6(L)-- --dict:19/20(L)--
Current allocation mode is local
GNU Ghostscript 6.53: Unrecoverable error, exit code 1

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Russell Shaw on June 18th, 2006


Richard Heathfield wrote:
Works ok for me

gs --version
8.15.1

Posted by Chris Uppal on June 18th, 2006


Richard Heathfield wrote:

I can't think of many editors (or similar) for Windows which care at
all about the final line's terminator. Some are even likely to remove
it silently.

I agree that Unix programs tend to expect a line-terminator after every
line, but Windows seems to use it more as a separator.

-- chris

Posted by Chris Uppal on June 18th, 2006


Huw Collingbourne wrote:

Haven't read the book yet, but just wanted to say that the download
page confused me. I expected the pictures of the "Little Book of Ruby"
to be clickable, or at least that there would be an obvious download
link. Not so. It took me a few minutes to realise that the "pdf" icon
was the download link. Normally when you see that icon on a webpage
with a downloadable PDF file it's a link to Adobe's site for
downloading "the" Acrobat Reader so I had just ignored that without
thinking...

-- chris

Posted by Huw Collingbourne on June 18th, 2006



"Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> wrote in message
news:xn0enmhppfkkhjl000@news.gradwell.net...

Thanks for the comments. I've now added a hyperlink to the main graphic plus
links to the captions underneath the pdf and zip icons.

best wishes
Huw



Posted by Richard Heathfield on June 18th, 2006


Chris Uppal said:

I know that vim /adds/ it silently if need be, which is fine because it's
obeying the file format requirements.

But you say that some are likely to /remove/ it. Do you *know* of any editor
that removes a terminating newline silently? Any text editor that takes
newlines out of a text file without my permission is a text editor I won't
ever be using again.

I just tested this on a Windows machine by downloading the code and
unzipping it there. Curiously, the TYPE command seems to write a newline at
the end of the file if need be. That is not something I'd noticed before.

Back to Ruby. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Posted by Chris Uppal on June 19th, 2006


Richard Heathfield wrote:

[me:]
I'm pretty sure that PFE does that sometimes. And almost any Windows
editor will "remove" the last line terminator if you go the the last
line, and type something without hitting return at the end.

I.e. in Windows it's a /separator/ not a /terminator/ -- not the same
as Unix.

So I don't think it's correct to talk of "the file format
requirements". Maybe the tools you use expect text with line
terminators. The tools /I/ use most often expect text with line
separators.

-- chris

Posted by Rob Thorpe on June 19th, 2006


Roberto Waltman wrote:
It's only trivial for now. Adobe are putting a lot of work into making
the PDF format very complicated to stop other readers from being able
to reliably read it.

This work is starting to pay off, I quite often find PDF files that
Ghostscript cannot open these days.


Posted by CBFalconer on June 19th, 2006


Rob Thorpe wrote:
That should be self-destructive. No one with any sense will buy
software that creates files that others cannot read.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html



Posted by Richard Heathfield on June 19th, 2006


CBFalconer said:

There's one (person with no sense) born every minute.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Similar Posts