Last active
February 21, 2017 17:06
-
-
Save BethKnight1234/8e7cb066ca6bc840a54ec0540f39b619 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. | |
Classes can change their states, Modules cannot. | |
2. Defining Modules | |
Modules hold methods that can be used across different classes. | |
module Doughy | |
def has_carbs? | |
true | |
end | |
end | |
class Pizza | |
include Doughy | |
end | |
Pizza.new.has_carbs? | |
3. What are two benefits modules provide us in Ruby? Elaborate on each. | |
They can DRY up our program by taking out repetative code. | |
Mix in modules into different classes. | |
They're really great for holding messages. Then you don't have to clutter your class with strings. | |
4. What values in Ruby evaluate as “falsy”? | |
Nil and False | |
5. Give 3 examples of “truthy” values in Ruby. | |
0 | |
"true" | |
true | |
6. List 3 HTTP Verbs | |
GET | |
POST | |
DELETE | |
7. HTTP Parsing: given the following HTTP Request, identify the following: | |
HTTP Verb: POST | |
Request Path: 127.0.0.1:9292 | |
Query Parameters: text/html | |
URL:127.0.0.1:9292/students?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 checkout -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 checkout master | |
git merge iteration-1 | |
9. Load Paths and Requires | |
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.map do |x| | |
x.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