class Products
Public Class Methods
new()
click to toggle source
# File lib/shopping2.rb, line 194 def initialize products=[ [1,'Da Vinci Code book', 250, 25], [2,'HP laptop', 50000, 10], [3,'Hibiscus shampoo', 150, 20], [4,'Cotton shirt', 1000, 30]] CSV.open('products.csv', 'w') do |csv| products.each {|record| csv << record } end end
Public Instance Methods
displayProducts()
click to toggle source
display the list of available products
# File lib/shopping2.rb, line 210 def displayProducts result = Array.new CSV.foreach('products.csv') do |record| result << record end puts "ID Product Price Qty." result.each do|item| puts item.join " " puts"\n" end end