Ruby in 100 Minutes (notes)

These are my notes from reading Ruby in 100 Minutes.

Note: I’m only making notes on things that were new to me while reading this. You may learn a lot of interesting stuff if you read the actual source, rather than my notes.

Lessons Learned

Ruby was originally developed by a developer named Matz in 1994 but it didn’t get popular until six years later, when it became a popular programming language in Japan. It remained a Japanese programming language (meaning there was no english documentation for it) until 2004/5 when 37signals empowered an engineer to use the language to build BaseCamp.

Now it’s a popular programming language.

—

“Ruby is an “interpreted” programming language which means it can’t run on your processor directly, it has to be fed into a middleman called the “virtual machine” or VM.” – JumpStartLabs

Virtual machine is either the IRB (which to me is a stage we go into via the terminal by typing irb + enter) or executing the programs via the command line.

—

Ruby reads right to left.

—

Ruby variable should be named after the meaning of their contents, not the type

—

Don’t include the word “array” when labeling arrays

For example: chocolate_types_array should be chocolate_types

Also, don’t abbreviate. Just spell stuff out.

For example: bkry_reno  should be spelled out to bakery_reno

—

When selecting positions in an array, you can use negative numbers to select from the back of the string.

For example: with the string greeting = “123456789”

–
greeting[2..-2]
Prints 345678

–
greeting[2...-2]
Prints 34567

—

String Concatenation

“hello, ” + variable | “!”

—

String Interpolation
name = "Ned"
puts "Good day, #{name}!"
#prints Good day, Ned!

Note: Interpolation tends to be shorter than Concatenation…
—
“Symbols are difficult to explain” – They are halfway between a string and a variable? They look like this:

:variable

Run the following through terminal… it’s crazy:
"hello".methods
"hello".methods.count
:hello.methods
:hello.methods.count

There is a lot going on in there… going to have to come back to this…

Think of a symbol as a “named integer.”

—

Two kinds of numbers – Integers (whole numbers) and Floats (have decimal points)
—

What does this mean – “Because Ruby’s integers are objects they have methods.” – I don’t get it.
5.times do
puts "hello, world!"
end

Simple. This just prints “Hello, world!” 5 times

—

Blocks are Sets of Instructions – Blocks = parameter passed into a method call

huh?

Blocks can be written many different ways.

Bracket Blocks = 5.times{ puts “Hello, World!” }

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.