Beginner stuff Flashcards
x valid name?
yes
y2 valid name
yes
_x valid name?
yes
7x valid name?
nope (starts with digit)
this_is_a_test valid name?
yes
this is a test valid name?
no(not a single word)
this’is@a’test!
no (contains invalid characters: ‘@!
this-is-a-test
invalid (looks like subtraction)
unless means the opposite of if (t/f)
True
x y
returns 0 if x and y are equal, 1 if x is higher, and -1 if y is higher
- times do puts “Test” end
5. times do { puts “Test” }
Test Test Test Test Test
loop that counts from 1 up to 5
1.upto(5) {…}
loop that counts from 10 down to 1
10.downto(1) {…}
loops that counts every 5th number up to 100
0.step(100, 5) {…}
1.upto(5) { |number puts number } // what is |number| mean?
allows you to get hold of the number being iterated. The number being iterated is being passed down to the variable “number”.
10 / 3 = ?
3
10.0 / 3 = ?
3.333…
x.to_f
converts x to floating point
Pi = 3.141592
constant that shouldnt me changed, but can
x = %q{…}
using quotation marks is only viable for a single line, but if you want to span multiple lines, you can use this.
x = «YOLO hi YOLO
«_space;marks the start of the string literal and is followed by a delimeter of your choice (YOLO) to end the block of code
“abc” * 3
abcabcabc
puts “x” > “y”
false (ruby compares the numbers that represent the characters in the string)
puts “y” > “x”
true (ruby compares the numbers that represent the characters in the string)