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 Array | |
| def group_by | |
| hash = Hash.new { |h,k| h[k] = [] } | |
| each { |i| hash[yield(i)] << i } | |
| hash | |
| 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
| 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) |
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 path_to_hotel?(day) | |
| car_rented?(day) || hotel_near_destination?(day) | |
| 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
| def hello | |
| "Hello World" | |
| 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
| module Measurable | |
| def area | |
| width * height | |
| end | |
| attr_reader :width, :height | |
| end | |
| class Rectangle | |
| include Measurable |
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 "sinatra" | |
| get "/next" do | |
| tell_itunes "next track" | |
| end | |
| get "/previous" do | |
| tell_itunes "previous track" | |
| 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
| def reduce(initial_value, &block) | |
| reduce_fun = fun(element, acc) { block(acc, element) } | |
| erl.lists.foldl(reduce_fun, initial_value, self) | |
| 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
| afsasf |
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 Contact | |
| def initialize(&block) | |
| instance_eval &block | |
| end | |
| def name(new_name=nil) | |
| @name = new_name if new_name | |
| @name | |
| 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
| ## 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 |