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 "date" | |
# def name_of_method(parameters) | |
def greeting(name) | |
return "Hello, #{name}" | |
end | |
# call the method giving it an argument | |
# puts greeting("Arthur") |
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
# 1. pick a price between 1 and 10 | |
number = rand(1..10) | |
# number = array.sample | |
puts number | |
guess = 0 | |
# LOOP HERE (stop if its correct guess) | |
until guess == number | |
# ask the user for his guess | |
puts "Pick a number from 1 to 10" |
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 "date" | |
def days_until_xmas() | |
# PSEUDO CODE | |
# 1. require date | |
# 2. set a variable with today's date | |
todays_date = Date.today | |
# 3. set another variable with xmas date (of this year) | |
xmas_date = Date.new(todays_date.year, 12, 25) | |
if todays_date > xmas_date |
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
beatles = ["john", "ringo", "seb"] | |
#index 0 1 2 (length - 1) | |
#index -3 -2 -1 | |
p beatles # puts beatles.inspect | |
# C R U D | |
# Create |
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
my_array = ["Ben", "Phelim", "Arthur"] | |
# indexes 0 1 2 | |
my_array.length # return the number of element in the array | |
# CRUD | |
# Read | |
my_array[0] # first element of array |
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
def acronymize(string) | |
string.split(" ").map { |word| word[0].upcase }.join | |
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
cities = ["london", "paris", "berlin"] | |
# 0 1 2 | |
# CREATE | |
# cities.push("olso") | |
cities << "madrid" | |
# READ | |
# p cities.last | |
p cities[3] |
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
def frequencies(text) | |
# intro downcase the string, and create an empty hash | |
frequency = {} | |
text = text.downcase | |
# 1. split the string into an array of words | |
words = text.split | |
# words => ["the", "lazy", ...] | |
# 2. iterate over the array | |
words.each do |word| |
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 'json' | |
require 'open-uri' | |
puts "Give username:" | |
print "> " | |
username = gets.chomp | |
# TODO - Let's fetch name and bio from a given GitHub username | |
url = "https://api.github.com/users/#{username}" |
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" | |
# fetch array of urls | |
puts "Fetching URLs" | |
urls = fetch_movie_urls | |
# return an array of hashes of movie details | |
movies = urls.map do |url| | |
puts "Scraping #{url}" |
OlderNewer