puts
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.variables
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
gets
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)to_i
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
to_s
method to convert to a string
one = 1.to_s
chomp
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
What are methods
Verbs of ruby Call or invoke Object.method Ex. Ten = 5.+(5)
When we call a method, we always use the format?
object.method
Arrays
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 = []