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
require "CSV" | |
items = [] | |
subtotal = 0 | |
input = nil | |
def read_csv(items) | |
i = 1 | |
CSV.foreach("products.csv", headers: true) do |entry| | |
items << {item_number: i, name: entry[1], price: entry[3], sku: entry[0]} | |
i += 1 |
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
favorite_movies = [ | |
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 }, | |
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 }, | |
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 } | |
] | |
favorite_movies.each {|movie| puts "#{movie[:year_released]}: #{movie[:title]}"} |
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
#!/usr/bin/env ruby | |
wordbank = ["tumble", "elixir", "falter", "erroneous", "sensible", "arrogant"] #Create wordbank with some words | |
word = wordbank.sample.upcase #Choose sample word from bank | |
unaltered_word = word.upcase #Word will be altered later, this is used for congrats message | |
previous_guesses = [] #Stores user's guesses to alert when re-use is attempted | |
target = "_"*word.length #Displays user's progress in guessing the word | |
counter = 8 #Create and display a counter for guesses | |
def add_guess(array, guess) #DRY's out adding old guesses to their array |
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
puts "Please enter item prices: " #prompts for item prices | |
input = gets.chomp | |
charges = [] | |
def total(array) | |
array.inject(0) {|total, each| total + each} | |
end | |
until input.downcase == "done" | |
charges << input.to_f |
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
#prompted for amount due | |
puts "How much does the customer owe?" | |
bill = gets.chomp.to_f.round(2) | |
#prompted for amount received | |
puts "How much did the customer pay?" | |
payment = gets.chomp.to_f.round(2) | |
#gives change and time of transaction or provides message and exits if not enough is provided | |
change = (payment-bill).abs | |
#if payment > bill return the difference of the two and the time | |
if payment > bill |
NewerOlder