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_relative "utilities" | |
| require_relative "scraping" | |
| puts "Welcome on Wishly!" | |
| wishlist = [{name: "Macbook", checked: true}, {name: "Iphone", checked: false}] | |
| while true | |
| display_menu | |
| action = gets.chomp |
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 'open-uri' | |
| require 'nokogiri' | |
| puts "Quelle catégorie t'intéresse?" | |
| category = gets.chomp | |
| url = "https://www.etsy.com/search?q=#{category}" | |
| file = open(url) | |
| html_text = file.read |
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
| cart = {} | |
| items = { | |
| "pomme" => {price: 3.5, stock: 100}, | |
| "orange" => {price: 1.5, stock: 20}, | |
| "quinoa" => {price: 5.0, stock: 30}, | |
| "pain" => {price: 1.2, stock: 10} | |
| } | |
| # Boucle de prise de commande |
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 "Bonjour, bienvenue à Longchamp" | |
| horses = ["Canaçon", "Sonic", "Belle des vents", "Bad boy"] | |
| while true | |
| puts "Voici les chevaux sur lesquels tu peux parier" | |
| horses.each_with_index do |horse, index| | |
| puts "Cheval numéro #{index + 1} - #{horse}" |
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
| def calculate(first, second, operation) | |
| if operation == "+" | |
| result = first + second | |
| elsif operation == "-" | |
| result = first - second | |
| elsif operation == "*" | |
| result = first * second | |
| elsif operation == "/" | |
| result = first / second | |
| else |
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 'open-uri' | |
| require 'nokogiri' | |
| # Let's scrape recipes from https://kitchenstories.io/en/search?search=strawberry | |
| puts "What's ingredient do you want recipes for?" | |
| ingredient = gets.chomp | |
| url = "https://kitchenstories.io/en/search?search=#{ingredient}" | |
| # Get the HTML file from the URL |
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
| # Validate data with =~ (to check it matches a regexp) | |
| welcome = "hello guys!" | |
| if text =~ /l{3}/ | |
| puts "This is nice welcome message" | |
| end | |
| email = "[email protected]" | |
| if email =~ /^\w+@\w+\.\w+$/ |
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
| def greet(first_name, last_name) | |
| full_name = "#{first_name.capitalize} #{last_name.capitalize}" | |
| yield(full_name) | |
| end | |
| greet("alice", "clavel") do |name| | |
| puts "Hallo freuilein #{name}" | |
| end | |
| greet("alice", "clavel") do |name| |
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
| musicians = ["Jimi Hendrix", "Bob Dylan", "Michael Jackson", "Barry White", "Justin Bieber"] | |
| # each: to iterate on elemens | |
| musicians.each do |musician| | |
| puts "Hello #{musician}" | |
| end | |
| # each_with_index: iterate on element + index | |
| musicians.each_with_index do |musician, index| | |
| puts "Musician N#{index} - #{musician}" |
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
| # While loop example | |
| price = rand(1..5) | |
| choice = nil | |
| while choice != price | |
| puts "What's your guess?" | |
| choice = gets.chomp.to_i | |
| end | |
| puts "You won" |
NewerOlder