Created
February 16, 2017 16:21
-
-
Save seth-at-at/4b297e88969e99b8c57b957da7900e10 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
1. Give one difference between Modules and Classes. | |
Modules are static, classes you can manipulate. | |
2. Defining Modules | |
module Doughy | |
def self.has_carbs? | |
true | |
end | |
end | |
class Pizza | |
include Doughy | |
def tasty? | |
true | |
end | |
end | |
3. What are two benefits modules provide us in Ruby? Elaborate on each. | |
Modules allow us to call reused methods from one place instead of rewriting them | |
Modules don't change so when using them from other classes we know what they will be. | |
4. What values in Ruby evaluate as “falsy”? | |
nil, false, | |
5. Give 3 examples of “truthy” values in Ruby. | |
0, true, 1.0,"hello", "" | |
6. List 3 HTTP Verbs | |
GET, POST, PUT | |
7. HTTP Parsing: given the following HTTP Request, identify the following: | |
HTTP Verb | |
POST | |
Request Path | |
/students | |
Query Parameters | |
?name=horace | |
8. Git and Branches: give a git command to accomplish each of the following: | |
Switch to an existing branch iteration-1 | |
git checkout iteration-1 | |
Create a new branch iteration-2 | |
git checkou -b iteration-2 | |
Push a branch iteration-2 to a remote origin | |
git push origin iteration-2 | |
Merge a branch iteration-1 into a branch master (assume you are not on master to begin with) | |
git merge origin master | |
9. Load Paths and Requires | |
Given a project with the following directory structure, give 2 ways that we could require file_one from file_two. | |
<you are here> | |
├── lib | |
│ │── file_one.rb | |
│ └── file_two.rb | |
require'./lib/file_one' | |
require_relative'file_one' | |
10. Refactoring: given the following snippet of code, show 2 refactorings you might make to improve the design of this code. | |
class Encryptor | |
def date_offset | |
date = Time.now.strftime("%d%m%y").to_i | |
date_squared = date ** 2 | |
last_four_digits = date_squared.to_s[-4..-1] | |
[last_four_digits[-4].to_i, | |
last_four_digits[-3].to_i, | |
last_four_digits[-2].to_i, | |
last_four_digits[-1].to_i] | |
end | |
end | |
Encryptor.new.date_offset | |
-------------------------------------------------------------- | |
class Encrytor | |
def initialize | |
@date = Time.now.strftime("%d%m%y") | |
end | |
def date_squared | |
@date.to_i ** 2 | |
end | |
def date_offset | |
last_four_digits = date_squared.to_s[-4..-1].split("") | |
last_four_digits.map do |num| | |
num.to_i | |
end | |
end | |
end | |
Encryptor.new.date_offset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment