Ruby Terms Flashcards
1
Q
puts
A
method which tells ruby to print out a string #correct puts ("Hello World!") puts can also print out numbers #correct puts (42) puts works with +, -, % (returns remainder) ect.
2
Q
variables
A
variable_example = "something you want to store" variable must be lowercase variable must not have space variable reassignment ... a = 3 a = 4 puts (a) #output 4
3
Q
gets
A
gets is a method. gets returns a string. #most basic name = gets #could look like name = gets ( )... but methods that don't have arguments don't need parenthesis #get print name puts ("enter name") name = gets puts (name)
4
Q
to_i
A
to_i is a method for converting to integer we use it like this. seven = "4".to_i + "3".to_i puts(seven) #output 7
5
Q
to_s
A
method to convert to a string
one = 1.to_s
6
Q
chomp
A
method used to keep everything on same line.
common use.
puts (“tell me your name”)
name = gets.chomp
can also use name.chomp if need to fix later
7
Q
What are methods
A
Verbs of ruby Call or invoke Object.method Ex. Ten = 5.+(5)
8
Q
When we call a method, we always use the format?
A
object.method
9
Q
Arrays
A
Arrays store sequences of objects, separated by commas.
array indices always start at zero.
cool_things = [“Racecars”, “Lasers”, “Aeroplanes”]
four_primes = [2, 3, 5, 7]
an_empty_array = []