For the Ruby Newbie (?) with programming experience

I have had exposure to multiple programming languages and have made a
lot of wrong assumptions about code snippets I was looking at while
attempting to get a handle on Ruby.

The Ruby Tutorial at this site is not a typical tutorial. It is short
and more like a collection of highlights (with code snippets) of the
ruby language.

I found it immensely useful it relating ruby to other languages I was
familiar with.

 http://www.fincher.org/tips/Languages/Ruby/

Did a search on URL so do not believe this has been posted before.

Don N. wrote:

 http://www.fincher.org/tips/Languages/Ruby/

Did a search on URL so do not believe this has been posted before.

This is a decent resource, but just beware that some of it is
non-idiomatic or misleading (in my opinion). For example, why is the 4th
example using global variables? In the 12th example, why are there
blocks after “if”?

Some of the file examples do not close the file and while this is
addressed, none of the examples use the much more common

File.open “filename” do |f|

end

which ensures the file is closed for you.

In example 22, there is this:

rescue TruncatedDataError #the last read had less chars than specified
#print the rest of the data. $! is the exception.

“.data” has the extra bytes

print $!.data.gsub(/</,"\r\n<")

I have never seen $! used, especially in this situation where one would
typically see

rescue TruncatedDataError => err
print err.data.gsub(/</,"\r\n<")

In example 37, the code shown is

require ‘startClicker’

when you should almost never be seeing camelcase for file names. (JRuby
might be the exception)

I don’t mean to pick on the author of the page (clearly they put a lot
of work into this), I just want you to be careful when emulating the
code on there.

-Justin