rails new <APP_NAME>
This file contains 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
# Setting min and max was a condition for making the | |
# game play by itself. | |
min_guess = 1 | |
max_guess = 1_000 | |
# Getting a random price that the player can try to guess. | |
price = rand(min_guess..max_guess) | |
# Starting a guesses counter, which will be incremented after | |
# each guess |
This file contains 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 Animal | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
def self.phyla | |
["phyla1", "phyla2", "phyla3", "phyla4"] | |
end | |
def eat(food) |
This file contains 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 SlotMachine | |
VALUES = %w[x cherry seven bell star joker] | |
def initialize(slots) | |
@slots = slots | |
end | |
def play | |
@slots = [ | |
VALUES[1..-1].sample, |
This file contains 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 "yaml" | |
require_relative "scraper" | |
puts "Getting top movies..." | |
top_50_movies_urls = top_movies | |
movies_infos = top_50_movies_urls.map do |url| | |
puts "Scraping... #{url}" | |
movie_info(url) | |
end |
This file contains 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_relative "xmas_list" | |
puts "Welcome to your Christmas gift list" | |
gifts = [ | |
{ name: "Necklace", bought: true }, # 0 | |
{ name: "Teddy Bear", bought: false }, # 1 | |
{ name: "Ring", bought: false } # 2 | |
] |
This file contains 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
# Ternary operator syntax | |
# condition ? truthy_statement : falsy_statement | |
def display_gifts(gifts_array) | |
gifts_array.each_with_index do |gift, index| | |
checkbox = gift[:bought] ? "[x]" : "[ ]" | |
puts "#{index + 1}. #{checkbox} #{gift[:name]}" | |
end | |
end | |
# Welcome (puts some welcome string to the user) |
This file contains 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
# - Create and assign to a variable, the store items | |
# fruit price | |
store_items = { kiwi: 1.25, apple: 9, coconut: 0.5 } | |
# - Create a cart | |
cart = { kiwi: 0, apple: 0, coconut: 0 } | |
puts "----------------------" | |
puts " Welcome to Instacart " |
This file contains 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
horse_names = ["Joel", "Andy", "Nadia", "Joey", "Filhinho Papai"] | |
puts "Welcome to the horse race" | |
balance = 100 | |
loop do | |
puts "-----=======-----" | |
puts "Here are the horses:" | |
horse_names.each_with_index do |name, index| | |
puts "#{index + 1}. #{name}" |
This file contains 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
horse_names = ["Joel", "Andy", "Nadia", "Joey", "Filhinho Papai"] | |
puts "Welcome to the horse race" | |
# [2BF] define a money variable starting at | |
loop do | |
puts "Here are the horses:" | |
horse_names.each_with_index do |name, index| | |
puts "#{index + 1}. #{name}" | |
end |
NewerOlder