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
| questions = {} # => create an empty Hash/object | |
| questions['one'] = "What's your name?" | |
| questions['two'] = "How old are you?" |
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
| arr = [3, "four", {five: 'six'}] |
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
| ages = [16, 15.6, 16.25, 17.1, 16.4, 15.8] | |
| total_years = 0.0 | |
| ages.each do |age| | |
| total_years += age | |
| end | |
| total_years / ages.size # => 16.191666666666666 |
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
| groceries = ["apple", "pear", "banana"] | |
| groceries.each do |grocery| | |
| puts grocery | |
| end | |
| # => | |
| # apple | |
| # pear | |
| # banana |
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
| questions = { | |
| 'one' => {text: "What is 2 + 2?", answer: 4}, | |
| 'two' => {text: "What is 4 + 7?", answer: 11}, | |
| 'three' => {text: "What is 7 + 3?", answer: 10}, | |
| } | |
| user_answers = { | |
| 'one' => 4, | |
| 'two' => 9, | |
| 'three' => 10 |
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
| # verbose | |
| if 2 + 2 == 4 | |
| puts "Correct!" | |
| end | |
| # short-hand | |
| puts "Correct" if 2 + 2 == 4 | |
| # more realistic short-hand | |
| def addition_problem(user_answer, correct_answer) |
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
| unless 2 + 2 == 4 | |
| puts "Incorrect!" | |
| end |
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 'date' | |
| def date_night? | |
| Date.today.wday == 5 # friday | |
| end | |
| unless date_night? | |
| puts "study hard!" | |
| end |
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
| str_a = 'j.p. morgan' | |
| str_b = 'jp morgan chase' | |
| str_a == str_b # => false | |
| str = 'j.p. morgan' | |
| str.downcase.gsub("j.p.", "jp").gsub("j.p", "jp").gsub("jp.", "jp").gsub("jp morgan", "jp morgan chase") # => "jp morgan chase" | |
| def jp_morgan_chase?(str) |
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
| brew install yarn | |
| rails new sample_app | |
| cd sample_app | |
| rails s | |
| # visit http://localhost:3000 in your browser | |
| rm -rf sample_app |