Skip to content

Instantly share code, notes, and snippets.

Andsbf / Messing_classes.rb
Created Mar 9, 2015
Classical Inheritence (Mini Exercise)
View Messing_classes.rb
require 'rspec'
RSpec.configure do |config|
config.color = true
#classes experiment!!!
module Flight
def fly
print("I'm #{self.class}, Sure I can fly")
Andsbf / pop_bottles_promotion.rb
Last active Aug 29, 2015
Pop Bottle Recycler
View pop_bottles_promotion.rb
require 'pry'
class Exchange
def initialize x_client
bottles_earned = {by_empty: 0, by_tips: 0}
bottles_earned[:by_empty] += x_client.bottles_empty/2
x_client.bottles_empty = x_client.bottles_empty%2
Andsbf / candidates.rb
Created Mar 9, 2015
Candidates Exercise
View candidates.rb
require 'active_support/all'
@candidates = [
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
Andsbf / regular_expression.rb
Created Mar 7, 2015
Regular Expressions Exercise
View regular_expression.rb
# 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)
!( /\b(\d){3}-(\d){3}-(\d){3}\b/ =~ string ).nil?
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
puts "has_sin? returns false if it doesn't have a SIN"
View benchmark_with_block.rb
def benchmark
# Your benchmarking code goes here.
start_time =
end_time =
running_time = end_time - start_time
View debug01.rb
require 'pry'
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'}
# Why is it returning nil instead of first element of the list above
p list.first
Andsbf / to_roman.rb
Created Mar 5, 2015
Roman Numerals Exercise
View to_roman.rb
require 'pry'
# require 'pry-nav'
def to_roman(num)
@roman_num = ""
@num = num
Andsbf / state_info.rb
Created Mar 5, 2015
States & Cities Exercise
View state_info.rb
# require 'pry'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
@states[:TX] = "Texas"
@states[:OK] = "OKlahoma"
Andsbf / count_letters.rb
Last active Aug 29, 2015
Character Counting Exercise
View count_letters.rb
require 'pry'
def count_letters (string="")
counts =
string.split("").each do |element|
# binding.pry
counts[element] += 1 if element != " "
View Sign shop exercise
def get_dimension_price
while true
puts "Input banner width in m:"
width = gets.chomp.to_f
break if (width != 0.0 && width < 150) # avoid string input and unreasonable values=a banner bigger than 150m
puts "Input banner height in m:"
height = gets.chomp.to_f