Last active
January 30, 2017 17:07
-
-
Save NicholasJacques/d7e71e0244ff2ba33d5f8d6dd90d2bed to your computer and use it in GitHub Desktop.
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
Floats and Integers | |
What’s the difference between a float and integer? | |
>> A Float has decimals while an integer is only whole numbers | |
What’s are the similarities and differences between BigNum and FixNum? | |
>> BigNum and FixNum are both classes. | |
>> * Bignum and FixNum both hold whole numbers, can't accomodate decimal points, both types of integers | |
>> * BigNum are over 18/19 digits | |
What will 4.0 / 2 return? | |
>> 2.0 | |
What will 1.5.to_i.to_f return? | |
>> 1.0 | |
What part of this expression ("hi" * 5?) is “syntactic sugar”? What does that mean? | |
>> You can't really multiply a word by a number but ruby gives you the ability to use a multiplier on a string | |
to print it multiple times. | |
What will 10 % 3 return? | |
>> 1 | |
What will 5 == 10/2 return? | |
>> True | |
How can you write 5 to the 2nd power? | |
>> (5 ** 2) | |
Strings | |
How can you grab the substring “ell” from “hello”? | |
>> "hello"[1..3] | |
Give an example of string concatenation and string interpolation. | |
>> h = "Happy" | |
>> f = "Festivus" | |
>> "Happy" + " " + "Festivus" => "Happy Festivus" | |
>> "Happy #{f}" => "Happy Festivus | |
>>Concatenation: | |
Give examples of three variable names: a “valid name” (it will work) that goes against Ruby style, an “invalid” name (it will trigger an error), and a valid and stylistically conventional name. | |
>> firstchal - Goes against ruby style because it does not use an underscore and abbreviates the word challenge. | |
>> 1stchal - invalid because number first | |
>> first_challenege - valid | |
Arrays | |
How do you add to an array? | |
>> you can use shovel or push or unshift | |
What will [1,2,3].shuffle do? | |
>> It will randomly shuffle the values within the array. | |
What do shift and unshift do? | |
>> shift removes the first element in an array, unshift removes the last. | |
Name 3 ways to retrieve 4 from this array: [4,3,5] | |
>> array = [4,3,5] array[0] | |
>> array.first | |
>> array[-3] | |
How would you print each word from this list (["hello", "goodbye", "cactus"]) to terminal within this output: | |
The word is "hello". | |
The word is "goodbye". | |
The word is "cactus". | |
>> array.each do { |item| puts "The word is #{item}" } | |
Flow control | |
What’s the difference between a while and until loop? | |
>> A while loop will iterate until the while is no longer true. An until loop will iterate until 'until' is true. | |
How do you escape a pry in the middle of a loop? | |
>> ctrl 'c' or type exit multiple times. If neither of those work then ctrl 'd'. | |
Enumerables (.each) | |
What is the purpose of an enumerable? | |
>> An enumerable evaluates every item in an array. | |
>> * works with collections | |
What are the two different ways that you can represent a block? | |
>> One line syntax: array.each do { |value| argument } | |
>> Multi line syntax: array.each do |value| | |
arguement | |
end | |
Given this array ["Beth", "Lauren", "Ilana"]. How would you create a new array of just the first initials of each name? | |
>> array.each do |name| | |
initial << name[0] | |
end | |
>> * array.map { |name| name[0] } | |
Classes and instance methods | |
When you’re defining a class, how do you store attributes? | |
>> Attributes are stored in instance variables | |
>> @name = name | |
What is the difference between attr_readers, attr_writers, and attr_accessors? What do each do? | |
>> attr_writer can be used to create a method that can assign every instance variable but not call them. | |
* replaces a setter method | |
>> attr_reader can be used to create a method that can call every instance variable but not change them. | |
* replaces getter method | |
>> attr_accessor can both read and write attributes. | |
* does both | |
What method corresponds with .new when you create a new instance of a class? | |
>> instance variables? .new() | |
>> * initialize | |
Methods, arguments and scopes | |
Describe the scope that methods create. Are variables created in that scope accessible elsewhere? | |
>> The scope of a method is local. Variables created within that method can only be accesed within that method. | |
What does the method scope have access to? | |
>> The method scope can access variables that are passed into it as well as its own local variables | |
>> Elapsed time: | |
>> 10:25 -10:48 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment