Skip to content

Instantly share code, notes, and snippets.

@kryptykphysh
Last active January 2, 2016 15:39
Show Gist options
  • Save kryptykphysh/8324981 to your computer and use it in GitHub Desktop.
Save kryptykphysh/8324981 to your computer and use it in GitHub Desktop.
Code solution for Suyesh Bhandari
class Sale
attr_accessor :b2b_total, :webpos_total
def initialize(b2b_total, webpos_total)
@b2b_total = b2b_total.to_i
@webpos_total = webpos_total.to_i
end
def total
@b2b_total + @webpos_total
end
end
# This code runs if the file is called from the command line
# with 'ruby sale_total.rb' (or whatever you call the file).
# You could also call the command with the values directly, using
# ARGV, which I can cover, if you like.
if $0 == __FILE__
# Get sale values from user.
print 'Enter B2B Total: '
b2b_total = gets.chomp.to_i
print 'Now enter Web POS Total: '
webpos_total = gets.chomp.to_i
# Instantiate new Sale object with values from user.
sale = Sale.new(b2b_total, webpos_total)
# Output the result of the Sale object's #total method.
puts "Total Sale: #{sale.total}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment