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
| shapes = [Square.new, Rectangle.new] | |
| def set_rectangle_width(shapes) | |
| shapes.each do |shape| | |
| shape.width = 5 | |
| shape.height = 6 | |
| 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
| >> vowels = [ "a", "e", "i", "o", "u"] | |
| >> vowels[0] | |
| => "a" | |
| >> vowels.size | |
| => 5 |
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 'dm-core' | |
| require 'dm-migrations' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'mysql://localhost/test') | |
| class Person | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :name, String, :required => true |
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
| (0..@santas.size - 1).each do |num| | |
| if @santas[num][:assignee][:last_name] == @santas[num][:assignment][:last_name] | |
| assign_santas | |
| 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
| class CoinChanger | |
| def initialize | |
| @purse = Hash.new(0) | |
| end | |
| def make_change(amount) | |
| if amount >= 25 | |
| change = amount % 25 | |
| @purse[:quarter] = amount/25 | |
| make_change(change) |
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
| applicant = Applicant.new(:name => "Meagan") | |
| if applicant.save | |
| # applicant is valid & saved | |
| else | |
| applicant.errors.each do |error| | |
| puts error | |
| 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
| require 'etc' | |
| class AccountProtectionProxy | |
| def initialize(real_account, owner_name) | |
| @subject = real_account | |
| @owner_name = owner_name | |
| end | |
| def deposit(amount) |
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 BritishTextObjectAdapter < TextObject | |
| def initialize(bto) | |
| @bto = bto | |
| end | |
| def text | |
| return @bto.string | |
| end | |
| def size_inches |
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
| w = SimpleWriter.new('out') | |
| class << w | |
| alias old_write_line write_line | |
| def write_line(line) | |
| old_write_line("#{Time.new}: #{line}") | |
| 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
| #html_report | |
| class HTMLReport < Report | |
| def output_start | |
| puts '<html>' | |
| end | |
| def output_head | |
| puts ' <head>' | |
| puts " <title>#{@title}</title>" | |
| puts ' </head>' |