rails new app_name --options-flags
3 2 1
rails g model Song title:string year:integer
app/models/song.rb
| '01': Ain | |
| '02': Aisne | |
| '03': Allier | |
| '04': Alpes-de-Haute-Provence | |
| '05': Hautes-Alpes | |
| '06': Alpes-Maritimes | |
| '07': Ardèche | |
| '08': Ardennes | |
| '09': Ariège | |
| '10': Aube |
| require_relative 'scraper' | |
| # Using movie getter to scrape top 5 urls | |
| movies_urls = movie_getter | |
| # Iterate over the urls to scrape movies | |
| movies = movies_urls.map do |movie_url| | |
| puts "Scraping #{movie_url}" | |
| # calls #scrape_movie, that returns a hash | |
| # that represents a movie, making our |
| require 'yaml' | |
| require_relative 'scraper' | |
| movie_urls = movie_getter | |
| File.open('movies_db.yaml', 'wb') do |file| | |
| movies_array = movie_urls.map do |movie_url| | |
| puts "Scraping #{movie_url}" | |
| scrape_movie(movie_url) |
| # Live-code: Voting age | |
| puts "What's your age?" | |
| age = gets.chomp.to_i | |
| minor = age < 18 | |
| unless minor | |
| puts "You can vote!" | |
| end |
| # The one we built | |
| def acronimyzer(sentence) | |
| # Capitalize sentence | |
| caps = sentence.upcase | |
| # Split words | |
| words = caps.split | |
| # Pick first letter of each word | |
| letters = [] |
| musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason'] | |
| # 0 1 2 3 | |
| puts musicians.length | |
| # Array CRUD | |
| # Create | |
| # musicians.push("Steven Wilson") | |
| musicians << "Steven Wilson" | |
| p musicians |
| def encrypt(message, encryption_key = -3) | |
| # Creates an alphabet array using a range | |
| alphabet = ("A".."Z").to_a | |
| # Converts the message (a String) into an upcased | |
| # array of letters | |
| letters = message.upcase.chars | |
| # Iterate (with #map) over each letter | |
| letters.map do |letter| |
| # 0 1 2 3 | |
| students = [ "Peter", "Mary", "George", "Emma" ] | |
| student_ages = [ 24 , 25 , 22 , 20 ] | |
| # Write a program that prints this: | |
| # Peter is 24 years old | |
| students.each_with_index do |student, index| | |
| age = student_ages[index] | |
| p "#{student} is #{age} years old" |