Sunday, August 5, 2012

an ongoing quick reference list of things i've learned

Methods are like verbs. It's like you're telling the code to do an action on something.

You use def method to define a method. Obviously.

to_s converts to a string.

to_i converts to an integer.

to_a converts to an array.

Hashes are ways of storing variables (like an array, but not in any specific order) and they use curlies: {}

class names must be capitalized. Learned that the hard way!

Variables with an @ are global variables (used throughout the entire program); otherwise, they are local variables (exclusive to the method).

Parameters are the things inside parentheses when you define a method: def like_this_here(parameter)

arg is a great abbreviation of the word "argument," which can be a placeholder for parameters. It also happens to sound like a pirate. def ahoy_mateys(arg)

A colon in front of a word makes it a symbol, which uses less memory than a string.

To insert an apostrophe, you can type \'. Like, "The bacon\'s burning!" And \n inserts a line break. These are called escape sequences. I guess because sometimes, you just need to get out?

<<NAME . . .  NAME allows you to type a multi-line paragraph. NAME can be anything!

Everything in Ruby is an object. Everything. (How many times have I heard this? Maybe repetition is the key.)

Good resources:
Ruby in 100 Minutes
String methods
Learn Ruby the Hard Way

No comments:

Post a Comment