Skip to content

Instantly share code, notes, and snippets.

@chrismdp
Created July 27, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismdp/4f18c16e1743a1f3db526a544b4c14f0 to your computer and use it in GitHub Desktop.
Save chrismdp/4f18c16e1743a1f3db526a544b4c14f0 to your computer and use it in GitHub Desktop.
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