Saturday, April 18, 2015

Learning Ruby part III

Starting flow control.
If statements.
Behavior as expected. Note the comparison operator uses double equals ==. A single = is an assignment operator.
Note that elsif is not spelled correctly. That took me a while to realize why the code didn't work right.
unless checks for false value, opposite of if
exclamation as a prefix is like "not" -- != means "not equal"
&& conjunction
|| disjunction
How to use if, else, and elsif
How to use comparators / relational operators like ==, !=, <, <=, >, and >=
How to use boolean / logical operators like &&, ||, and !

String control with a daffy duckifyer. gsub

Check substrings .include?

Starting loops
while, until, for
no increment operator like ++ or --
instead, uses += with an delta value
range in 1...10 (exclude the end value) or in 1..10 (include end value)

loop method -- the iterator
break to exit a loop
next to skip an iteration
arrays to store multiple values
another iterator .each

Learning Ruby part II

Basic tutorial at code.org was just that -- basic.
Now I'm trying their next tutorial, which seems to deal with input and string manipulation.

gets accepts user input
gets inserts a blank line after the input. the method .chomp removes the line
gets.chomp accepts user input without adding an extra line

Monday, April 13, 2015

Learning Ruby part I

I have been given a task which requires I learn Ruby. I will try.

I've installed Ruby on my laptop (from links at ruby-lang.org). I found a tutorial on code academy. So I'll see where this leads.

notes:
data types: number, boolean, and string
assignment operator: equal sign
exponentiation: **
modulo: %
print: sends to screen
puts: adds blank line after screen output. hmmm?
I see. print leaves the next output right there, puts goes to the beginning of the next line.

strings have .length
and .reverse
and .upcase and .downcase

hashmark for single line comments
=begin to =end for multi-line comments