Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? No mocks/stubs allowed.
#
# (Here's @seacreature's take)
class Quiz
def initialize(input = STDIN, output = STDOUT)
@input = input
@output = output
module RAAWS
ONE_NECESSARY_SEARCH_PARAM =%w<
Actor Artist AudienceRating Author
Brand BrowseNode Composer Conductor CityDirector
Keywords Manufacturer MusicLabel Neighborhood
Orchestra Power Publisher TextStream Title>
class ItemOperation < Operation
def self.lookup(item_id, index=nil, &block)
IMAGE_TYPES = %w( image/jpeg image/png image/pjpeg image/x-png image/gif )
validates_attachment_content_type :image, :content_type => IMAGE_TYPES
acc += (e.is_a?(Hash) && e.has_key?(:colspan)) ? e[:colspan] : 1
cell_text = cell.is_a?(Hash) ? cell[:text] : cell.to_s
if cell.is_a?(Hash) && cell[:colspan]
text = e.is_a?(Hash) ? e[:text] : e.to_s
width = if e.is_a?(Hash) && e.has_key?(:colspan)
## Extract Class (http://refactoring.com/catalog/extractClass.html)
class Person
attr_accessor :name, :office_area_code, :office_number
def telephone_number
[office_area_code, office_number].join('-')
end
end
module Measurable
def area
width * height
end
attr_reader :width, :height
end
class Rectangle
include Measurable
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"
# inspired by some code from Chris Wanstrath (shared w. me by Ryan Smith)
# https://gist.github.com/25455
#
# heavily modified by Gregory Brown at this point..
def context(*args, &block)
return super unless (name = args.first) && block
@practicingruby
practicingruby / gist:1232567
Created September 21, 2011 16:34 — forked from stevemorris/gist:1232537
Circuitry
module Circuitry
extend self
def []=(name, definition)
circuits[name] = definition
end
def [](name)
circuits[name]
end