This file contains hidden or 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
| def benchmark | |
| # Your benchmarking code goes here. | |
| start_time = Time.now | |
| yield | |
| end_time = Time.now | |
| puts @duration = end_time - start_time | |
| end |
This file contains hidden or 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
| # Determine whether a string contains a SIN (Social Insurance Number). | |
| # A SIN is 9 digits and we are assuming that they must have dashes in them | |
| def has_sin?(string) | |
| match = string.match(/\b\d{3}\-\d{3}\-\d{3}\b/) | |
| !!match | |
| end | |
| puts "has_sin? returns true if it has what looks like a SIN" | |
| puts has_sin?("please don't share this: 234-604-142") == true |
This file contains hidden or 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
| require 'active_support/all' | |
| require 'pp' | |
| @candidates = [ | |
| { | |
| id: 5, | |
| years_of_experience: 4, | |
| github_points: 293, | |
| languages: ['C', 'Ruby', 'Python', 'Clojure'], | |
| date_applied: 5.days.ago.to_date, | |
| age: 26 |
This file contains hidden or 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
| class Car | |
| def initialize(model, colour) | |
| @model = model | |
| @colour = colour | |
| end | |
| end |
This file contains hidden or 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
| require 'rubygems' | |
| require 'rest-client' | |
| fname = "sample.txt" | |
| somefile = File.open(fname, "w") | |
| somefile.puts "Hello file!" | |
| somefile.close |
This file contains hidden or 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
| require 'csv' | |
| # Represents a person in an address book. | |
| # The ContactList class will work with Contact objects instead of interacting with the CSV file directly | |
| class Contact | |
| attr_accessor :name, :email | |
| # Creates a new contact object |
This file contains hidden or 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
| class Barracks | |
| attr_reader :gold, :food | |
| def initialize | |
| @gold = 1000 | |
| @food = 80 | |
| end | |
| def train_footman |
This file contains hidden or 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
| ### SETUP | |
| require 'rspec' | |
| ### LOGIC (fix me) | |
| def who (word) | |
| word | |
| end | |
| def hello(who) | |
| "hello #{who}!" |
This file contains hidden or 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
| gem 'rspec' | |
| gem 'pry' | |
| gem 'byebug' |
This file contains hidden or 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 | |
| SELECT editions.isbn | |
| FROM editions | |
| INNER JOIN publishers | |
| ON (editions.publisher_id = publishers.id) | |
| WHERE (publishers.name = 'Random House'); | |
| #2 | |
| SELECT editions.isbn, books.title | |
| FROM editions | |
| INNER JOIN publishers |