Created
January 12, 2021 12:24
-
-
Save Haumer/a30d8b86ab99ae48c55d9684d3f25fde to your computer and use it in GitHub Desktop.
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 greetings(name) | |
"Welcome to London #{name}! I hope you enjoy it!" | |
end | |
# puts greetings("James") | |
# puts greetings("Nathan") | |
# def one_plus_one | |
# 1 + 1 | |
# end | |
# puts one_plus_one | |
# def double(number) | |
# 2 * number | |
# end | |
# puts double(20) | |
# def multiply(first_number, second_number) | |
# first_number * second_number | |
# end | |
# puts multiply(3, 10) | |
# def nice_name(first_name, last_name) | |
# name = "#{first_name.upcase} #{last_name.capitalize}" | |
# return name | |
# end | |
# puts nice_name("Alex", "hauMer") | |
# puts nice_name("Ed", "Melech") | |
# def tomorrow | |
# tomorrow_date = Date.today + 1 | |
# return tomorrow_date.strftime("%B %d") | |
# end | |
# puts tomorrow | |
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
# Stings | |
"Hello Batch 523" | |
"1985".to_i | |
# Integers | |
1 | |
2 + 5 | |
4 * 2 | |
10.to_s | |
10.to_f | |
# Floats | |
1.0 | |
2.0 + 5.0 | |
4.0 * 2.0 | |
7.0 / 2.0 # yields a result with decimal places | |
# Arrays | |
[] | |
[1, 2, 3] | |
["Hello", "batch", "523"] | |
["Hello", 2, true] # mixed array | |
["London", "birmingham", "manchester"] | |
# 0 1 2 | |
# Booleans | |
true | |
false | |
nil | |
# Range | |
(1..10).to_a # creates an array form 1 to 10 | |
(1...10).to_a # excludes upper bound | |
# ------------------------------------------- | |
# Concatenation | |
age = 23 | |
"I am" + " " + age.to_s + " " + "years old" | |
# Interpolation | |
"I am #{age} years old!" # needs double quotes | |
"I am #{20 * 8} years old!" |
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
# age = 99 | |
# puts "Hello, I am #{age} years old!" | |
# puts "Next year I will be #{age + 1} years old!" | |
# we_typically_use_snake_case # varibale syntax | |
city = "London" | |
population = 7000000 | |
mayor = "Sadiq Khan" | |
puts "The city of #{city} has a population of #{population} and the mayor is #{mayor}!" | |
mayor = "Boris Johnson" | |
puts "In the past #{city} had a population of #{population / 2} and the mayor was #{mayor}" | |
puts population | |
population = population + 1 | |
# population += 1 # shortcut for above | |
puts population | |
population = population - 10 | |
# population -= 10 # shortcut for above | |
puts population | |
# cmd + / | |
# cmd + d | |
# cmd + shift + d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment