Skip to content

Instantly share code, notes, and snippets.

@seth-at-at
Created January 27, 2017 17:47
Show Gist options
  • Save seth-at-at/cf1625b4332b9fd7bcf839b482aa718f to your computer and use it in GitHub Desktop.
Save seth-at-at/cf1625b4332b9fd7bcf839b482aa718f to your computer and use it in GitHub Desktop.
#Floats and Integers
What’s the difference between a float and integer?
* Floats are exact values while Integers are rounded to the nearest whole number
What’s are the similarities and differences between BigNum and FixNum?
* Fixnum is () Bignum is ()
What will 4.0 / 2 return?
* 2.0
What will 1.5.to_i.to_f return?
* 2.0
What part of this expression ("hi" * 5?) is “syntactic sugar”? What does that mean?
* the (*) is syntactic sugar, it makes it look nicer and easier to read instead of typing out "hi" five 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”?
* (1..4)
Give an example of string concatenation and string interpolation.
* "Hello #(name)" "Hello" + "#{name}"
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.
* 1stname
* &varname
* first_name
# Arrays
How do you add to an array?
* [] << variable
What will [1,2,3].shuffle do?
* rearrange the order
What do shift and unshift do?
* add and remove from the beginning of the array
Name 3 ways to retrieve 4 from this array: [4,3,5]
* array[0]
* shift(0)
* array[-3]
How would you print each word from this list (["hello", "goodbye", "cactus"]) to terminal within this output:
* array.each {|word| puts "The word is #{word}."}
# Flow Control
What is the purpose of an enumerable?
* It makes it easier to sort things
What are the two different ways that you can represent a block?
* Looping, (while, until, if)
* using .each and .map and having a |word| arguement
Given this array ["Beth", "Lauren", "Ilana"]. How would you create a new array of just the first initials of each name?
* array.map {|word| new_arr << word[0]}
# Classes and Instance Methods
When you’re defining a class, how do you store attributes?
* def initialize
What is the difference between attr_readers, attr_writers, and attr_accessors? What do each do?
* attr_readers, allow you to check and read the attributes outside of the code
* attr_writers, allow you to change the attributes outside of the code
* attr_aaccessors, allow you to do both
What method corresponds with .new when you create a new instance of a class?
* initialize
# Methods, Arguements and Scope
Describe the scope that methods create. Are variables created in that scope accessible elsewhere?
* scopes that methods create are global and accessable by other methods, but the variables inside of those methods are instance methods and inaccessable outside of the method
What does the method scope have access to?
* the method scope has access to it's own variables, global variables and other methods, but not other methods instance variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment