Skip to content

Instantly share code, notes, and snippets.

View caioertai's full-sized avatar
🔮
Klatchian Coffee Guzzler

Caio Andrade caioertai

🔮
Klatchian Coffee Guzzler
  • Mexico City
View GitHub Profile
# 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

Rails Quiz - 879

1. How do you create a Rails app?

rails new <APP_NAME> 

2. How do you start coding a Rails project? Give the right sequence.

class Animal
attr_reader :name
def initialize(name)
@name = name
end
def self.phyla
["phyla1", "phyla2", "phyla3", "phyla4"]
end
def eat(food)
class SlotMachine
VALUES = %w[x cherry seven bell star joker]
def initialize(slots)
@slots = slots
end
def play
@slots = [
VALUES[1..-1].sample,
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
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
]
# 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)
# - 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 "
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}"
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