Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
afsasf
def reduce(initial_value, &block)
reduce_fun = fun(element, acc) { block(acc, element) }
erl.lists.foldl(reduce_fun, initial_value, self)
end
require "rubygems"
require "sinatra"
get "/next" do
tell_itunes "next track"
end
get "/previous" do
tell_itunes "previous track"
end
module Measurable
def area
width * height
end
attr_reader :width, :height
end
class Rectangle
include Measurable
def hello
"Hello World"
end
def path_to_hotel?(day)
car_rented?(day) || hotel_near_destination?(day)
end
def distance_to_hotel(day, index)
case
when index >= @grid.size - 1
''
when day[:lodgings].empty?
UNKNOWN_DISTANCE
when overnight_transport?(day)
OVERNIGHT_TRANSPORT_LABEL
when day[:arrive]
day[:arrive].distance_from(hotel_location(day)
class Array
def group_by
hash = Hash.new { |h,k| h[k] = [] }
each { |i| hash[yield(i)] << i }
hash
end
end
module PlayingCards
class Card
attr_accessor :rank, :suit
def initialize(a_rank, a_suit)
@rank = parse_rank a_rank
@suit = parse_suit a_suit
end
require "minitest/autorun"
require_relative "../lib/ivory_tower"
require_relative "shared/allowed_units"
# adopted from: https://gist.github.com/839034
def context(*args, &block)
return super unless (name = args.first) && block
context_class = Class.new(MiniTest::Unit::TestCase) do
class << self