forked from turingschool-examples/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed exercise 1 of objects and methods
- Loading branch information
1 parent
38edcc8
commit 0eb3f20
Showing
8 changed files
with
82 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Bag | ||
|
||
def initialize | ||
@candies = [] | ||
end | ||
|
||
def empty? | ||
candies.empty? | ||
end | ||
|
||
def candies | ||
@candies | ||
end | ||
|
||
def count | ||
candies.count | ||
end | ||
|
||
def <<(candy) | ||
@candies << candy | ||
end | ||
|
||
def contains?(type) | ||
candies.any? do |candy| | ||
candy.type == type | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Candy | ||
attr_reader :type | ||
def initialize(type) | ||
@type = type | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Costume | ||
attr_reader :style | ||
def initialize(style) | ||
@style = style | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class TrickOrTreater | ||
|
||
def initialize(costume) | ||
@costume = costume | ||
@bag = Bag.new | ||
end | ||
|
||
def dressed_up_as | ||
@costume.style | ||
end | ||
|
||
def bag | ||
@bag | ||
end | ||
|
||
def has_candy? | ||
!bag.empty? | ||
end | ||
|
||
def candy_count | ||
bag.count | ||
end | ||
|
||
def eat | ||
bag.candies.pop | ||
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
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
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
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