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 ChangeDispenserCashregister | |
attr_accessor :total, :payment, :change_to_dispense | |
COINS = { quarter: 25, dime: 10, nickel: 5, penny: 1 } | |
def initialize | |
get_total | |
get_payment |
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 Interpolater | |
attr_accessor :data, :template | |
def initialize(template, data) | |
@template = template | |
@data = data | |
replace_bracketed_words | |
end |
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 Member | |
attr_accessor :username, :streak_dates | |
def initialize(username) | |
@username = username | |
@streak_dates = [] | |
end | |
def practice | |
self.streak_dates << Date.today unless self.streak_dates.include?(Date.today) |
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 Streak | |
attr_accessor :username, :streak_dates | |
def initialize | |
@streak_dates = [] | |
end | |
def extend_streak | |
self.streak_dates << Date.today unless self.streak_dates.include?(Date.today) | |
end |
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 Book | |
attr_accessor :title, :author | |
def initialize(args) | |
args = defaults.merge(args) | |
@title = args[:title] | |
... | |
end | |
def store_book | |
# logic for storing the book at a location on the shelf |
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 Shelf | |
... | |
def store(@book) | |
# logic to find the correct location on itself for @book | |
end | |
end | |
class Book | |
attr_accessor :title, :author | |
def initialize(args) |
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 Shelf | |
... | |
def store(book) | |
length = book.length | |
width = book.width | |
depth = book.depth | |
# logic to find the nearest spot that can accomodate the given dimensions | |
end | |
end |
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 Book | |
.... | |
def initialize(args) | |
args = defaults.merge(args) # If you're using Ruby <2.0, this is the way to go. | |
@title = args[:title] | |
@author = args[:author] | |
end | |
def defaults | |
{title: "Unknown", author: "Unknown"} | |
end |
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 Book | |
.... | |
def initialize(title: 'Unknown', author: 'Unknown') # This is the Ruby >= 2.0 syntax. | |
@title = title | |
@author = author | |
end | |
end |
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 Shelf # without the wrapper | |
... | |
def store(book) | |
# imagine complicated logic here... | |
intermediate_result = book.storage_requirements / self.capacity | |
# imagine more complicated logic... | |
end | |
end | |
class Shelf # with wrapper |
OlderNewer