-
-
Save chrismdp/4f18c16e1743a1f3db526a544b4c14f0 to your computer and use it in GitHub Desktop.
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 Checkout | |
def initialize | |
@total = 0 | |
end | |
PRICES = { "Apple" => 30, "Banana" => 50 } | |
def scan(item) | |
@total += PRICES[item] | |
end | |
def total | |
@total | |
end | |
end | |
checkout = Checkout.new | |
checkout.total # will print 0 | |
checkout.scan("Apple") | |
checkout.total # will print 30 | |
############################ | |
def plus(count) | |
string = "" | |
count.times do |x| | |
string += yield(x + 1) | |
end | |
string | |
end | |
puts plus(3) { "ding" } | |
puts plus(3) { |x| "...#{x}" } | |
puts plus(5) { |x| (x + 2).to_s } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment