Ruby Terms Flashcards

You may prefer our related Brainscape-certified 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

to_s

A

method to convert to a string

one = 1.to_s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are methods

A
Verbs of ruby
Call or invoke
Object.method
Ex.
Ten = 5.+(5)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When we call a method, we always use the format?

A

object.method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 = []

How well did you know this?
1
Not at all
2
3
4
5
Perfectly