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
add_game "Civilization" do | |
system "PC" | |
year 1991 | |
end | |
add_game "The Legend of Zelda", "NES", 1986 | |
with_game "The Legend of Zelda", "Civilization" do | |
print_details | |
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
add_game "Civilization" do | |
system "PC" | |
year 1991 | |
end | |
add_game "The Legend of Zelda", "NES", 1986 |
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 Game | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
@year = nil | |
@system = nil | |
end | |
def year(value) |
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
LIBRARY = Library.new | |
def add_game(name, &block) | |
game = Game.new(name) | |
game.instance_eval(&block) | |
LIBRARY.add_game(game) | |
end | |
def with_game(name, &block) | |
game = LIBRARY.find_by_name(name) |
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
add_game "Civilization" do | |
system "PC" | |
year 1991 | |
end | |
with_game "Civilization" do | |
print_details | |
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 Game | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
@year = nil | |
@system = nil | |
end | |
def year(value) |
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 Library | |
def initialize | |
@games = [] | |
end | |
def add_game(game) | |
@games << game | |
end | |
def find_by_name(name) |
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
add_game "Civilization" do | |
system "PC" | |
year 1991 | |
end | |
with_game "Civilization" do | |
# We'll add some code to operate on the game later | |
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
add_game "Civilization" do | |
system "PC" | |
year 1991 | |
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 Library | |
def initialize | |
@games = [] | |
end | |
def add_game(game) | |
@games << game | |
end | |
end |