Skip to content

Instantly share code, notes, and snippets.

@samlandfried
Last active January 30, 2017 17:07
Show Gist options
  • Save samlandfried/26b7111d28fb911c5d96cb15f8ebbed8 to your computer and use it in GitHub Desktop.
Save samlandfried/26b7111d28fb911c5d96cb15f8ebbed8 to your computer and use it in GitHub Desktop.

Floats and Integers

What’s the difference between a float and integer?

An integer is a whole number, a float includes a decimal value

What’s are the similarities and differences between BigNum and FixNum?

A bignum is a number that exceeds the storage capacity of a fixnum. I'm not sure at ### what point that distinction occurs, and I'm not sure what different methods are available on both.

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?

The "*" is syntactic sugar (meaning shorthand) for a multiplication method. The "?" might also be sugar, but I'm not sure.

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. concatenation = "Hel" + "lo" interpolation = "Two plus two is #{2 + 2}" 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. bad style = javaScriptVar invalid = 1st_val good = times_bubbled

Arrays

How do you add to an array? shoveling, pushing, shifting

What will [1,2,3].shuffle do?

return an array with those three values in random order. Possibly [3,1,2]

What do shift and unshift do?

They insert and remove the first value from an array. Name 3 ways to retrieve 4 from this array: [4,3,5] [4,3,5][0] [4,3,5].first [4,3,5].unshift 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 |word| puts "The word is "#{word}"" end

Flow control

What’s the difference between a while and until loop?

A while loop operates if the condition evaluates to true, and the until loop iterates if the condition evaluates to false How do you escape a pry in the middle of a loop? exit

Enumerables (.each)

What is the purpose of an enumerable?

To operate on every value of a collection

What are the two different ways that you can represent a block?

do end && {} Given this array ["Beth", "Lauren", "Ilana"]. How would you create a new array of just the first initials of each name? new_array = [] array.each do |name| new_array << name[0] end

Classes and instance methods

When you’re defining a class, how do you store attributes? Many different ways, but I believe a conventional method would be defining them in the initialize method

What is the difference between attr_readers, attr_writers, and attr_accessors? ### What do each do?

Read/write access.

What method corresponds with .new when you create a new instance of a class?

I don't know. (Initialize)

Methods, arguments and scopes

Describe the scope that methods create. Are variables created in that scope accessible elsewhere?

What does the method scope have access to?

A new, local scope is created when a method is defined. Variables within that scope are not accessible outside. It does not have access to global variables unless they are fed into the method as an argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment