This file contains 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 Recipe | |
attr_reader :recipe | |
def initialize(recipe) | |
@recipe = recipe | |
standardize | |
end | |
private |
This file contains 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
$ ruby strings.rb [1.8.7-p357] | |
user system total real | |
double quote | |
assignment: 1.580000 0.000000 1.580000 ( 1.575944) | |
+: 8.750000 0.000000 8.750000 ( 8.746774) | |
<<: 9.660000 0.010000 9.670000 ( 9.668061) | |
interpolation: 8.870000 0.000000 8.870000 ( 8.869000) | |
single quote | |
assignment: 1.570000 0.000000 1.570000 ( 1.570190) | |
+: 8.580000 0.000000 8.580000 ( 8.581263) |
This file contains 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 Foo | |
extend self | |
def initialize(*args) | |
super | |
end | |
end | |
class Bar | |
def initialize |
This file contains 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
C:\>irb | |
irb(main):001:0> require 'rubygems' | |
=> true | |
irb(main):002:0> require 'rdoc' | |
=> true | |
irb(main):003:0> puts $LOAD_PATH | |
C:/Dropbox/apps/Ruby-192-p180/lib/ruby/site_ruby/1.9.1 | |
C:/Dropbox/apps/Ruby-192-p180/lib/ruby/site_ruby/1.9.1/i386-msvcrt | |
C:/Dropbox/apps/Ruby-192-p180/lib/ruby/site_ruby | |
C:/Dropbox/apps/Ruby-192-p180/lib/ruby/vendor_ruby/1.9.1 |
This file contains 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 round(n) | |
cents = n * BigDecimal("100") | |
remainder = cents % BigDecimal("1") | |
if remainder == BigDecimal("0") | |
n | |
elsif remainder < BigDecimal("0.5") | |
n.round(2, BigDecimal::ROUND_DOWN) | |
elsif remainder > BigDecimal("0.5") | |
n.round(2, BigDecimal::ROUND_UP) |
This file contains 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 MyModule | |
extend self | |
attr_accessor :log_results | |
@log_results = true | |
def parse | |
if @log_results == true | |
puts "logging results" |
This file contains 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 GitStats | |
module CLI | |
extend self | |
def parse(argv) | |
options = parse_options(argv) | |
end | |
private | |
This file contains 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 RobotFactory | |
def self.next_direction(factory_floor) | |
# same code as before, however, instead of printing "GO WEST" | |
# or "GO EAST" return those as strings. | |
end | |
private | |
def count_impacts | |
# same code as before |
This file contains 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 bankers_round(amount) | |
scaled_amt = amount * BigDecimal("100") | |
if scaled_amt.frac > BigDecimal("0.5") | |
return scaled_amt.ceil / BigDecimal("100") | |
elsif scaled_amt.frac < BigDecimal("0.5") | |
return scaled_amt.floor / BigDecimal("100") | |
end | |
return scaled_amt.floor / BigDecimal("100") if scaled_amt.to_i.even? |
This file contains 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 Rates | |
def initialize(rates_xml) | |
@rates = {} | |
@rates_xml = rates_xml | |
end | |
def rate(from, to) | |
@rates["#{from}:#{to}"] ||= derive_rate(from, to) | |
end |