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 RackApp | |
def call(env) | |
[200, {"Content-Type" => "text/html"}, ["Hello Rack! - you requested #{env["REQUEST_PATH"]}"]] | |
end | |
end | |
run RackApp.new | |
# lambda.call -- rack uses .call | |
#run lambda { |env| [200, {"Content-Type" => "text/html"}, [env.to_s]] } |
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 Integer | |
def to_roman | |
numeral = "" | |
number = self | |
hash = {1000 => "M", 900 => "CM", 500 => "D", 400 => "CD", 100 => "C", 90 => "XC", 50 => "L", 40 => "XL", 10 => "X", 9 => "IX", 5 => "V", 4 => "IV", 1 => "I"} | |
hash.each do |key, value| | |
until number < key | |
numeral << value |
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
RSpec.configure do |config| | |
# Use color in STDOUT | |
config.color_enabled = true | |
# Use color not only in STDOUT but also in pagers and files | |
config.tty = true | |
# Use the specified formatter | |
config.formatter = :progress # :progress, :html, :textmate | |
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
class Integer | |
@@conversion = { | |
1 => ['I', 'V', 'X'], | |
2 => ['X', 'L', 'C'], | |
3 => ['C', 'D', 'M'], | |
4 => ['M', 'M', 'M'] | |
} | |
def to_roman | |
numeral = self |
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
# Download this file: | |
# https://gist.github.com/aviflombaum/28534c5d69edd2439a7d/download | |
# Run it from your terminal with: | |
# ruby ruby.basics.rb | |
# (Just make sure you are in the right directory) | |
# ====================================== | |
# Ignore All This Code | |
# ====================================== |
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 Person | |
def initialize(attributes) | |
attributes.each do |attribute_name, attribute_value| | |
##### Method one ##### | |
# Works just great, but uses something scary like eval | |
# self.class.class_eval {attr_accessor attribute_name} | |
# self.instance_variable_set("@#{attribute_name}", attribute_value) | |
##### Method two ##### | |
# Manually creates methods for both getter and setter and then |
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 TriangleError < StandardError | |
end | |
class Triangle | |
def initialize(s1, s2, s3) | |
@sides = [s1, s2, s3] | |
if @sides.any? {|side| side <= 0} | |
raise TriangleError.new, "Cannot create a triangle " | |
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
class School | |
attr_accessor :roster | |
def initialize(name) | |
@roster = {} | |
end | |
def add_student(name, grade) | |
@roster[grade] ||= [] | |
@roster[grade] << name |
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 'simplecov' | |
SimpleCov.start | |
require 'json' | |
require 'rspec' | |
require_relative '../lib/jukebox' | |
require_relative '../lib/song' | |
#use this song data for your tests | |
songs = [ |
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
# # Binary Secret Handshake | |
# > There are 10 types of people in the world: Those who understand binary, and those who don't. | |
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake". | |
# ``` | |
# 1 = wink | |
# 10 = double blink | |
# 100 = close your eyes |