Created
June 3, 2014 22:51
-
-
Save lcbunch/12ac7a3ba5fc3596d90e to your computer and use it in GitHub Desktop.
Ruby Quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. What is the difference between a local variable, and an instance variable? | |
local variable is only applicable to immediate context | |
instance variable is available throughout the class | |
2. What is the datatype of `"DevPoint Labs"`? | |
string | |
3. Assign the number `10` to the local variable `n`. | |
n = 10 | |
4. Assign your name to the local variable `name`. | |
name = "Lisa" | |
5. What is an Array? | |
an array is a general collection of indexes | |
6. Give an example of when you’d use an Array. | |
hotel room numbers | |
7. What is a method? | |
a method is a performable action on an object; it is like a verb | |
8. Name 3 iterator methods for an Array. | |
.each | |
.collect | |
.map | |
9. Name 3 methods for a String. | |
.length | |
.capitalize | |
.reverse | |
10. What datatype does `5 / 2` return? | |
string | |
11. What is a Hash? | |
a hash is a collection of specific key-value pairs that can be called upon | |
12. Give an example of when you’d use a Hash. | |
could be used for contact information (name, address, etc) | |
13. What is a class? | |
a class is a blueprint for an object and is a constant | |
14. True or False; A class is a constant. | |
True | |
15. `true` and `false` are called what? | |
boolean values | |
16. Write 4 conditional operators. | |
if | |
elsif | |
else | |
end | |
case | |
when | |
end | |
while | |
do | |
end | |
until | |
do | |
end | |
17. Create a method called bucket that returns an empty array. | |
def bucket() | |
return(array.new) | |
end | |
18. Name 6 ruby special keywords. (a keyword is a word that already has a special meaning) | |
true | |
false | |
case | |
for | |
unless | |
initialize | |
19. How would you convert a number into a string? | |
.to_s | |
20. How would you convert a string into a number? | |
.to_i | |
21. What is class inheritance? | |
class inheritance is when one class assumes all methods of another | |
22. What are modules used for? | |
modules are used to contain multipul constants and methods so they | |
can share functionality and be free of name conflicts | |
23. What is a gem? | |
a gem is a packaged Ruby program | |
24. Name 4 gems, and their purposes. | |
Rails - web framework to make developers' lives easier | |
activeadmin - gem for generating adminstration style interfaces | |
chronic - date/time parser | |
money - ruby library for dealing with money and currency conversion | |
25. What are comments used for in programming? | |
to leave notes to yourself and others that don't affect the program | |
26. In Ruby, only 2 things evaluate to `false`. What are they? | |
false and nil | |
27. Write 2 comparison operators. | |
>= | |
<= | |
28. Write the code for “ if dave’s age is greater than or equal to 21” | |
if daves_age >= 21 | |
29. Instantiate a `Car` class. | |
volkswagen = Car.new | |
30. What is a method chain? | |
using several methods right after another | |
31. How would you capitalize and reverse a string then print it out to the console? | |
puts string.capitalize.reverse | |
32. What is a method to add an object to an array? | |
<< | |
33. How would you add an object to a hash? | |
hash[:a] << "value" | |
34. What are 2 valid datatypes of keys for a hash? | |
string and symbol | |
35. What is a writer method? | |
method to assign a value to an attribute | |
36. What is a reader method? | |
method that returns a value from an attribute | |
37. There are 4 types of variables. What are they? | |
local, @instance, @@class, $global | |
38. What does the question mark at the end of a method in ruby mean? | |
it is asking if the object is true or false only | |
39. What’s a common way to debug your code? | |
use Ruby's debugger; -rdebug in command line | |
40. How would you return the string `"two"` from this array? `arr = ["one", "two", "three"]` | |
puts arr[1] | |
41. How would you return the string `"DevPoint"` from this hash? `hsh = {:name => "DevPoint"}` | |
puts hsh[:name] | |
42. What is the datatype for `:age`? | |
symbol | |
43. What is the datatype for `-36.98`? | |
float | |
44. What is the datatype for `[1, 2, 3]`? | |
array | |
45. What is the datatype for `"BOOM goes the dynamite"`? | |
string | |
46. What is the datatype for `123412`? | |
fixnum | |
47. What is the datatype for `{:food => "burger"}`? | |
hash | |
48. What is the datatype for `false`? | |
FalseClass | |
49. What is the purpose of `nil`? | |
to tell you something doesn't make sense; it can't evaluate to true or false | |
50. How would you print out the current date? | |
I don't remember. I remember Jeremy showing us this stuff one class | |
but I don't have notes on it and didn't figure it out with google. | |
51. How would you print out just the current year without using a Fixnum? | |
as a string "2014" | |
52. What is String interpolation? | |
a way to include a variable inside of a string | |
53. What is String concatenation? | |
joining 2 strings into 1 | |
54. What does OOP stand for? | |
object oriented programming | |
55. What does instantiation mean? | |
to create a new instance of an object | |
56. What is the name of the method that is called every time an object is instantiated? | |
initialize | |
57. What are arguments? | |
a way to pass a variable into a method | |
58. How do you pass an argument? | |
by running the method with different variables | |
59. Write a method called `eat` that has an argument `food` with a default value of `"cheese"`. | |
def eat(food = "cheese") | |
end | |
60. What is a loop? | |
a sequence of instructions that runs until conditions are met | |
61. How long has ruby been around? | |
19 years | |
62. How are you doing on this quiz so far? | |
alright I guess. | |
63. Is anyone else hungry? | |
I'm sure somewhere. | |
64. What are the pipe characters used for in a block? | |
the pipe characters give a variable to the block to be performed upon | |
65. What is the difference between single quote strings and double quote strings? | |
string interpolation only works with double quotes and double quotes can use more | |
escape sequences | |
66. Name some rules for naming a method? | |
can't begin with a number, can contain upper and lower case, but should start | |
with lower case, may contain _, !, ?, and = | |
67. How can you tell if a method is an instance or class method? | |
class methods start with self. | |
68. In an instance method, what is `self`? | |
nothing | |
69. How do you add a dependency to a file? | |
I don't know. | |
70. I have a text file called `names.txt`. Each name is on it's own line. How would you print all the names in the file? | |
don't know | |
71. When a method defines an argument that has a asterisk in front of a variable name, what is that asterisk referred to? e.g. `def thing(*stuff)` | |
splat operator | |
72. When a method defines an argument that has an ampersand in front of a variable name, what is that ampersand and variable name collectivly called? e.g. `def thing(&stuff)` | |
don't know | |
73. What is it called when you see the `do` and `end` keywords together? | |
Do you mean literally, like do/end? or in the block sense where | |
something is acted upon? | |
74. What does DRY stand for? | |
Don't Repeat Yourself | |
75. What does DSL stand for? | |
Domain Specific Language | |
76. This question left blank intentionally. | |
77. What does MRI stand for? | |
Mat'z Ruby Interpreter | |
78. What is the difference between JRuby and MRI? | |
MRI uses C code, and JRuby uses Java | |
79. What would you use RubyMotion for? | |
for developing and testing applications for Apple products | |
80. Does your head hurt? | |
yes |
jasonwc
commented
Jun 3, 2014
- Indexes isn't the right word. Everything in Ruby is called an _______
- The shovel operator '<<' doesn't work for hashes. Only arrays.
- Look into Time.now and the strftime method.
- See above.
- Look into requiring files in Ruby.
- Look into the encryptor app we made in class.
- That's a hard one to Google, but it's there!
- Block is the answer we were looking for.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment