I need to learn

I would like to learn Ruby so I am looking at getting “Programming
Ruby”. I am also looking at converting stuff to RoR, so I was looking
at getting “Agile Web D. with Rails”.

Would those be good?

Robert

On 3/12/07, Robert H. [email protected] wrote:

I would like to learn Ruby so I am looking at getting “Programming
Ruby”. I am also looking at converting stuff to RoR, so I was looking
at getting “Agile Web D. with Rails”.

Would those be good?

Robert

Hi,

Programming Ruby is good.
You can see the 1st edition online.

http://www.rubycentral.com/book/

I haven’t read “Agile Web D. with Rails” yet.

Harry

http://www.kakueki.com/ruby/list.html
Japanese Ruby List Subjects in English

I have both. My personal opinion, and I am biased, is that
the ruby book is very good. I (still) often use it for reference.

The Rails book well … I think a disadvantage is that it is
very speficic to rails. I often saw people asking ruby
questions, which lead me to the FIRM opinion, that everyone that
really wants to use rails, needs to learn ruby too. (Doesnt
have to learn everything but must understand basic stuff,
such as :symbols, hashes arrays AND be able to use
them. Oh and of course, irb too… on IRC it happens too often
that people on rails dont know irb, and it can
be frustrating to tutor people that are only, mostly interested
in rails)

Anyway to your questions, Programming Ruby is definitely worth it.

And the RoR book probably only when you need to use RoR too :wink:

On 3/11/07, Robert H. [email protected] wrote:

Would those be good?

Yes.

Marc H. wrote:

on IRC it happens too often
that people on rails dont know irb, and it can
be frustrating to tutor people that are only, mostly interested
in rails)

I don’t understand the distinction between “learning irb” and “learning
Ruby”. For instance, if I am going to write a hello world program, I
open up a text editor, type in the code, save it, and then run it by
typing:

ruby myProgram.rb

I realize that you could do the same thing in irb, but editing is easier
in a text file. So, as far as I can tell, you don’t ever have to use
irb to learn Ruby. Is there something important about irb that I am
missing?

On Sun, 11 Mar 2007 19:32:34 -0700, Robert H. wrote:

I would like to learn Ruby so I am looking at getting “Programming
Ruby”. I am also looking at converting stuff to RoR, so I was looking
at getting “Agile Web D. with Rails”.

Would those be good?

I’m still pretty new to Ruby myself and found the Rails book, well,
confusing. Rails is a framework built with Ruby and the book isn’t aimed
at helping you with Ruby itself.

The first edition (not the second edition which covers 1.8) of
“Programming Ruby - The Pragmatic Programmer’s Guide” is online:

http://www.ruby-doc.org/docs/ProgrammingRuby/

So you could take a look before you buy a copy (of the second edition)
to
see what you think.

And look around ruby-doc.org, there’s some very useful info there.

On Mar 12, 2007, at 1:34 AM, 7stud 7stud wrote:

open up a text editor, type in the code, save it, and then run it by
typing:

ruby myProgram.rb

I realize that you could do the same thing in irb, but editing is
easier
in a text file. So, as far as I can tell, you don’t ever have to use
irb to learn Ruby. Is there something important about irb that I am
missing?

I don’t think you’re missing anything. If you use a text editor with
first-class support for Ruby (e.g., TextMate on OS X), your need for
irb rapidly approaches zero.

Irb is often cited as a great way to do exploratory coding such as
checking on what methods are available to an object. I can do
exploratory coding without firing up irb because I can evaluate code
snippets from within a TextMate edit buffer. Here is an example, cut
from TextMate and pasted here:

(Array.new.methods - Object.new.methods).sort # => ["&", "*", "+", "-", "<", "[]", "[]=", "all?", "any?", "assoc", "at", "clear", "collect", "collect!", "compact", "compact!", "concat", "delete", "delete_at", "delete_if", "detect", "each", "each_index", "each_with_index", "empty?", "entries", "fetch", "fill", "find", "find_all", "first", "flatten", "flatten!", "grep", "include?", "index", "indexes", "indices", "inject", "insert", "join", "last", "length", "map", "map!", "max", "member?", "min", "nitems", "pack", "partition", "pop", "push", "rassoc", "reject", "reject!", "replace", "reverse", "reverse!", "reverse_each", "rindex", "select", "shift", "size", "slice", "slice!", "sort", "sort!", "sort_by", "to_ary", "transpose", "uniq", "uniq!", "unshift", "values_at", "zip", "|"]

Further, in a TextMate edit buffer, I can highlight any method name
and get the ri documentation on the method just by hitting ctrl-H. I
also find it easy to run unit tests and benchmarks from within
TextMate – two things I find awkward to do from irb.

But my point is not to sing the praises of TextMate. I like a lot,
but there are other editors that can perform the same or similar
feats. My main point is a really good code editor trumps irb.

Regards, Morton

Morton G. wrote:

On Mar 12, 2007, at 1:34 AM, 7stud 7stud wrote:

open up a text editor, type in the code, save it, and then run it by
typing:

ruby myProgram.rb

I realize that you could do the same thing in irb, but editing is
easier
in a text file. So, as far as I can tell, you don’t ever have to use
irb to learn Ruby. Is there something important about irb that I am
missing?

I don’t think you’re missing anything. If you use a text editor with
first-class support for Ruby (e.g., TextMate on OS X), your need for
irb rapidly approaches zero.

Irb is often cited as a great way to do exploratory coding such as
checking on what methods are available to an object. I can do
exploratory coding without firing up irb because I can evaluate code
snippets from within a TextMate edit buffer. Here is an example, cut
from TextMate and pasted here:

(Array.new.methods - Object.new.methods).sort # => ["&", "*", "+", "-", "<", "[]", "[]=", "all?", "any?", "assoc", "at", "clear", "collect", "collect!", "compact", "compact!", "concat", "delete", "delete_at", "delete_if", "detect", "each", "each_index", "each_with_index", "empty?", "entries", "fetch", "fill", "find", "find_all", "first", "flatten", "flatten!", "grep", "include?", "index", "indexes", "indices", "inject", "insert", "join", "last", "length", "map", "map!", "max", "member?", "min", "nitems", "pack", "partition", "pop", "push", "rassoc", "reject", "reject!", "replace", "reverse", "reverse!", "reverse_each", "rindex", "select", "shift", "size", "slice", "slice!", "sort", "sort!", "sort_by", "to_ary", "transpose", "uniq", "uniq!", "unshift", "values_at", "zip", "|"]

Further, in a TextMate edit buffer, I can highlight any method name
and get the ri documentation on the method just by hitting ctrl-H. I
also find it easy to run unit tests and benchmarks from within
TextMate – two things I find awkward to do from irb.

But my point is not to sing the praises of TextMate. I like a lot,
but there are other editors that can perform the same or similar
feats. My main point is a really good code editor trumps irb.

Regards, Morton

Thanks for the response. I’m actually interested in TextMate as well.
Do you know if I can create my own auto completion snippets in TextMate.
For instance, I currently use an editor where I can assign any character
sequence to a code snippet. Then if I type the character sequence and
hit the space bar, the code snippet is entered. I also use the auto
completion a lot just for long method names; I type one or two
characters and hit the space bar, and bang, the method name is inserted.
It’s very easy to add new character sequences and the corresponding code
I want attached to the character sequence. It’s also an extremely fast
to have the space bar as the trigger for the auto completion.

Let’s just say that irb is worth learning to use and useful to know.
It can be a lot quicker than Creating a new file, changing
permissions on it and executing it. You can explore side effects and
snippets very quickly. You can even open a file’s contents in irb.
One thing is for sure, if you have Ruby on a system, you have irb.
While learning Ruby, irb is useful.
TextMate is easy enough to start using, but like all good editors
there is a learning curve. The auto completion isn’t what you might
expect from a full IDE like XCode or VisualWhatever. But it is a good
quality app with a small footprint, not demanding of the system, and
pretty robust.
The cool thing is the way TextMate just implements existing OS X
software to do things like test run your code or validate or preview
pages. It’s really sort of a testament to the volume of good
libraries in the Cocoa framework being used in ways they are meant to
be used.
At first I wasn’t sure if it was worth the price, but the more I used
it, I quickly felt it was worth more.

On Mon, Mar 12, 2007 at 11:06:48AM +0900, Marc H. wrote:

I have both. My personal opinion, and I am biased, is that
the ruby book is very good. I (still) often use it for reference.

I have both books and I recommend them highly. The style suits me well:
logically presented, lots of examples, easy to search, minimal padding.

The Rails book well … I think a disadvantage is that it is
very speficic to rails.

To me, that’s an advantage. When I buy a 700-page book about Rails, I
want
most of those pages to be about Rails. This is the DRY principle applied
to
paper :slight_smile:

The Agile RoR book has a 13-page appendix about Ruby itself, but more as
a
taster than anything. If the OP is planning to buy both books, then I
think
he’ll be happy with both. You’re right that he shouldn’t just by the RoR
book by itself, unless he’s already learned most of Ruby online.

Regards,

Brian.

On Mon, Mar 12, 2007 at 10:35:08AM +0900, Robert H. wrote:

I would like to learn Ruby so I am looking at getting “Programming
Ruby”. I am also looking at converting stuff to RoR, so I was looking
at getting “Agile Web D. with Rails”.

Would those be good?

The short answer: “It depends.”

Programming Ruby, also known as “the Pickaxe” because of the pickaxe on
the front cover, is an excellent book for people who are already
programmers in (an)other language(s). It’s also a very nice reference
to have on your shelf. If you’re a brand new, or relatively novice,
programmer, you might want to choose something that does a little more
hand-holding in the early stages of learning Ruby (and learning to
program in general). Programming Ruby basically assumes you know most
of the concepts of programming that come up in the first few chapters,
but don’t know how they apply in Ruby.

So – if you’re a programmer already, Programming Ruby’s an excellent
choice. If you’ve never programmed before, or have only barely touched
program source code (such as doing some very simple imperative stuff
with PHP or JavaScript), you’d probably be better served by choosing a
book like Chris P.'s “Learning to Program”.

There’s now an effective middle road, in the form of another book called
“Everyday Scripting with Ruby”. You might want to have a look at that
while you’re deciding as well. There are other books available, but
these are the three with which I’m familiar that I know are at least
reasonably good. In fact, from what I’ve seen, all three are truly
excellent – they just target different audiences. They are also,
conveniently, all published under the Pragmatic Programmers imprimatur.

“Agile Web D. with Rails” is also an excellent book, but not
for learning Ruby, per se. It’s an excellent book for learning Rails
itself, the framework. You really don’t need to know much Ruby to do
basic Rails development – though if you start using Rails heavily you
will definitely benefit from learning Ruby itself pretty heavily. If
you’re already a PHP web developer, you should be able to get started
with Rails pretty quickly with the Rails book by starting with the
appendix that gives a brief overview of the Ruby language. That’ll help
you translate programming concepts from a language like PHP to Ruby,
insofar as is needed to do basic work with Rails. Surprise: Agile Web
Development with Rails is also a Pragmatic Programmers book, and of a
high quality similar to the others I’ve mentioned.

While I’m talking about the PragProgs, I should mention where the
Pragmatic Programmers name arose: Some time ago, Dave T. and Andrew
Hunt wrote a book called The Pragmatic Programmer. It doesn’t teach any
particular programming language, and in fact doesn’t teach you to
program, really. It does, however, provide excellent details on how to
be a good programmer, once you already know how to program,
regardless of the language. I recommend it wholeheartedly, as one of
the seminal works of programming practice.

Back on topic: If you’re serious about Rails, and want to start with
Rails then move into Ruby, I suspect that the second book you should
pick up after Agile Web D. is a book called “Ruby for Rails”.
I haven’t had a chance to go through it at all, but by reputation it is
an excellent book as well, and teaches Ruby programming from a Rails
perspective, going beyond merely teaching the framework and the minimum
of Ruby knowledge necessary to use Rails.

I hear good things about “The Ruby Way”, as well. I salivate for this
book, and will probably get it next month. It’s probably a good second
or third Ruby book (depending on how much programming you know when you
start with Ruby and how quickly you learn the language).

Neither Ruby for Rails nor The Ruby Way is a Pragmatic Programmers book,
but don’t let that deter you. I’ve heard nothing but glowing
recommendations in relation to these two books. I can’t personally
vouch for them, but I certainly have heard enough to be reasonably sure
I wouldn’t waste my money to purchase them.

I hope that helps.

On Mon, Mar 12, 2007 at 02:34:48PM +0900, 7stud 7stud wrote:

typing:

ruby myProgram.rb

I realize that you could do the same thing in irb, but editing is easier
in a text file. So, as far as I can tell, you don’t ever have to use
irb to learn Ruby. Is there something important about irb that I am
missing?

Actually, irb is basically just a command shell that uses Ruby as its
scripting language, rather than something like bash, csh, or DOS batch
files. It’s an exceedingly nice command shell, though, and is worth
learning for its own sake – I use it as my calculator application,
among other things. It helps with testing snippets of code when you
want to test them before including them in a file you’re editing, and
you can use it for interactive language exploration.

When I’m actually writing “serious” Ruby code, of course, I save it to a
file in my text editor (I use Vim for that). I find that irb serves as
an indispensable aid a lot of the time, however. Your mileage may vary.

You don’t have to use irb to learn Ruby, but sometimes it’s pretty
nice anyway.

On Mar 12, 2007, at 4:13 AM, 7stud 7stud wrote:

Thanks for the response. I’m actually interested in TextMate as well.
Do you know if I can create my own auto completion snippets in
TextMate.
For instance, I currently use an editor where I can assign any
character
sequence to a code snippet. Then if I type the character sequence and
hit the space bar, the code snippet is entered.

You can do this with TextMate although the tab key is the key used to
complete code snippets. For a particular (i.e., frequently used)
snippet, dedicated shortcuts can assigned in place of tab completion
if you so wish. For instance, if you highlight the two lines

foo = bar
zot ||= []

and hit cntrl-shift-W, inserts the code snippet

begin
foo = bar
zot ||= []
rescue Exception => e

end

The ‘Exception’ and the ‘e’ are place holders. Hitting tab will
select them for immediate in-place editing.

I also use the auto completion a lot just for long method names; I
type
one or two characters and hit the space bar, and bang, the method name
is inserted. It’s very easy to add new character sequences and the
corresponding code I want attached to the character sequence. It’s
also
an extremely fast to have the space bar as the trigger for the auto
completion.

TextMate maintains auto-completion for all the tokens you have in an
edit buffer. You don’t have to specify any character sequences. The
escape key is the auto-completion key. You type the first few
characters of a token and hit escape. If the first completion offered
isn’t the one you want, hit escape again. The completions are offered
in most-recently-used order.

Regards, Morton

On Mar 12, 2007, at 4:51 AM, John J. wrote:

Let’s just say that irb is worth learning to use and useful to
know. It can be a lot quicker than Creating a new file, changing
permissions on it and executing it.

I think a lot depends on one’s work habits. I have TextMate open all
the time, but not Terminal. So it’s quicker for me to evaluate
snippets in TextMate than to open a terminal window and fire up irb.
There is no need to set permissions to run code from TextMate.

You can explore side effects and snippets very quickly. You can
even open a file’s contents in irb. One thing is for sure, if you
have Ruby on a system, you have irb.
While learning Ruby, irb is useful.
TextMate is easy enough to start using, but like all good editors
there is a learning curve.

James Edward G. II can be your friend here. First, there’s his book
“TextMate Power Editing for the Mac” and then there’s his screencast
“Ruby Unit Tests and More” (free download from iTunes Store – search
key “TextMate”).

The auto completion isn’t what you might expect from a full IDE
like XCode or VisualWhatever.

You’re right, but it works well all the same.

But it is a good quality app with a small footprint, not demanding
of the system, and pretty robust.
The cool thing is the way TextMate just implements existing OS X
software to do things like test run your code or validate or
preview pages. It’s really sort of a testament to the volume of
good libraries in the Cocoa framework being used in ways they are
meant to be used.
At first I wasn’t sure if it was worth the price, but the more I
used it, I quickly felt it was worth more.

Regards, Morton

Morton G. wrote:

On Mar 12, 2007, at 4:13 AM, 7stud 7stud wrote:

When I’m actually writing “serious” Ruby code, of course, I save it to a
file in my text editor (I use Vim for that). I find that irb serves as
an indispensable aid a lot of the time, however. Your mileage may vary.

Is there a way to get Vim to automatically indent code?

the tab key is the key used to
complete code snippets.
…if you highlight the two lines

foo = bar
zot ||= []

and hit cntrl-shift-W, inserts the code snippet

I don’t get the digit gymnastics that most text editors require you to
perform to use auto completion. Is there no way to bind the auto
completion to the space bar in TextMate? If you’ve never coded with
space-bar auto-completion, you haven’t lived! The type of auto
completion I’m talking about seems like such a simple feature to
implement: you have a flat text file with a list of character sequences
and the corresponding code(phrase, name, whatever), and then the typing
the characters plus hitting the space bar produce the code.

Personally, I’ve never really liked the Xcode, MS Visual C++ style of
auto completion where a list pops up–it’s just too slow to find what
you want in the list. I just started using Xcode, and I don’t have
anything favorable to say about it. I can’t even get it to properly line
up nested braces when using this style of braces:

void myFunc()
{

}

I mean matching up braces has to be the most basic requirement of any
IDE, but Xcode(2.4) can’t do it for nested braces. Ridiculous.

Sorry to the op for the thread drift. I also want to thank everyone
else for the really insightful posts on good Ruby books and text
editors.

Let’s try that again:
Here’s my new .vimrc file:

set autoindent
syntax on
ab sf someName

7stud 7stud wrote:

Morton G. wrote:

On Mar 12, 2007, at 4:13 AM, 7stud 7stud wrote:

When I’m actually writing “serious” Ruby code, of course, I save it to a
file in my text editor (I use Vim for that). I find that irb serves as
an indispensable aid a lot of the time, however. Your mileage may vary.

Is there a way to get Vim to automatically indent code?

I figured it out.

lol. Lookie what I found:
Personalizing vim

:ab abbreviation Full text, spaces are ok

What happens is when you type the abbreviation in vim, as soon as you
hit the space bar it is expanded to the full text. The abbreviation dmv
in the prior example would expand to “Department of Motor Vehicles.” If
you close vim these settings are lost unless you commit them to your
.vimrc file.

Here’s my new .vimrc file:

set autoindent “keeps the indenting the same when you hit
return”
syntax on "turns on syntax highlighting
ab sf someName "auto-completion sequence: type abbreviation,
hit space bar to expand

On Mar 12, 2007, at 5:28 AM, 7stud 7stud wrote:

I don’t get the digit gymnastics that most text editors require you to
perform to use auto completion. Is there no way to bind the auto
completion to the space bar in TextMate? If you’ve never coded with
space-bar auto-completion, you haven’t lived! The type of auto
completion I’m talking about seems like such a simple feature to
implement: you have a flat text file with a list of character
sequences
and the corresponding code(phrase, name, whatever), and then the
typing
the characters plus hitting the space bar produce the code.

Morton was showing an unusual TextMate example above. Typically in
TM you type a sequence and push tab. For example, try these in TM:

ea-tab
inj-tab
ase-tab

James Edward G. II

On 3/12/07, Chad P. [email protected] wrote:

Back on topic: If you’re serious about Rails, and want to start with
Rails then move into Ruby, I suspect that the second book you should
pick up after Agile Web D. is a book called “Ruby for Rails”.
I haven’t had a chance to go through it at all, but by reputation it is
an excellent book as well, and teaches Ruby programming from a Rails
perspective, going beyond merely teaching the framework and the minimum
of Ruby knowledge necessary to use Rails.

I might suggest that “Ruby for Rails” might be a good book to start
with. It covers both Ruby and Rails in a spiral fashion, giving you a
little Ruby, then a little Rails, then going back in more depth.

It doesn’t cover Ruby as deeply as the pickaxe, and it doesn’t cover
Rails as deeply as AWDWR (and it’s based on Rails 1.1 whereas AWDWR
2nd ed is more up-to-date covering the recently released Rails 1.2),
but as an introduction to both Ruby and Rails as a whole it’s probably
not a bad place to start.

Now my experience was based on first reading the 1st ed of the pickaxe
on-line, then either the 1st ed of AWDWR or the 2nd ed of the Pickaxe
(or the other way around), then Ruby for Rails and AWDWR 2nd ed (sort
of in parallel). So I don’t really know what it would have been like
to start with Ruby for Rails, any more than someone of my age knows
what it would be like to encounter Star Wars for the first time in the
the order Episode 1, 2, 3, 4, 5, 6.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Mar 12, 2007, at 8:32 AM, James Edward G. II wrote:

and hit cntrl-shift-W, inserts the code snippet
typing
the characters plus hitting the space bar produce the code.

Morton was showing an unusual TextMate example above. Typically in
TM you type a sequence and push tab. For example, try these in TM:

ea-tab
inj-tab
ase-tab

Actually, the point I wanted to get across was that, for code
snippets, the user can change from tab-invoked completion to shortcut-
key invocation (or vice-versa) at will. As usual, I didn’t express
myself very clearly.

Regards, Morton