Repository navigation
Expand file tree
/
Copy pathindex.rb
More file actions
49 lines (26 loc) · 2.42 KB
/
Copy pathindex.rb
File metadata and controls
49 lines (26 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Question 1: What is a variable?
# Question 2: What Ruby method can you use to make a loop from an array?
# Question 3: In Ruby, what are the booleans?
# Question 4:
# a. In Ruby what is coercion? Explain what coercion is using the code snippet below.
# if nil
# puts "hi"
# end
# Question 5: What is a class?
# Question 6: What is an instance variable?
# Question 7: What is handy about using gems in Ruby?
# Question 8: Use string interpolation and the variable my_string = “Fred” to print to output the string “My name is Fred”
# Question 9: Give one method to remove whitespace from user input in Ruby
# Question 10: What method would you use to get input from a user?
# Question 11: What result would you get for this equation: 2 + 7 % 3 ? Remember the order of operations!
# Question 12: Name one method you could use to access the last element in an array
# Question 13: What the method do you use to create new objects (or instances of a class)?
# Question 14:
# a. Define a class called fish.
# b. Add an initialize method, it should contain two attributes, name and species, they should be accessible for reading and writing
# c. Create one fish object (nemo) and store it in a variable, it should contain the correct number of arguments that will be used for nemo's attributes
# Question 15: Define a hash called ‘student’. This hash should have two keys, one called name, and the other called age, and assign a string to the name key, and an integer to the age key.
# Question 16: Write a Ruby method that takes three arguments and returns the sum (total) of those three arguments.
# Question 17: Write a Ruby method that takes an array and a string as arguments, and returns true if the string is in the array, and false if it is not. Use a loop in this method. You can use .each but you CANNOT use .include?
# Question 18: Write a method that takes one argument, a number, and that returns true if the number is divisible by three, and false otherwise.
# Question 19: You must use your previous method in this next question. Write another method that takes an array (of numbers) as an argument. This method will use your first method to return two arrays (within one array - an array of arrays) The first array contains the numbers that are divisible by 3, and the other contains the rest of the numbers. For example, if you pass the second method the array [9, 4, 3, 5, 30, 2, 8] it would return [[9, 3, 30],[4, 5, 2, 8]].