Created
July 13, 2021 09:59
-
-
Save Haumer/69b8696e9a6015c49d4c4404f84b3b25 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" | |
# STRING => needs quotes | |
"london" | |
"" | |
age = 29 | |
name = "Alex" | |
# puts "#{name} is #{age}" # string interpolation | |
# puts '#{name} is #{age}' | |
# puts "vienna".upcase | |
# puts "PARIS".downcase | |
# puts "nEw yOrk".capitalize | |
"29".to_i | |
# puts "Alex" + " " + "Haumer" # concatenation | |
# 'london\'s greatest' | |
# "london's greatest" | |
# INTEGER | |
1 | |
2312312 | |
-1 | |
29.to_s | |
20.even? #=> true | |
20.odd? #=> false | |
1 + 1 #=> 2 | |
1.class #=> Integer | |
1.to_f | |
# FLOAT | |
3.14 | |
1.0 | |
10.0.to_i | |
# BOOLEANS | |
true | |
false | |
1 == 1 #=> true | |
age < 18 #=> false | |
1.positive? # method with quesiton marks return booleans | |
# RANGE | |
1..10 | |
"a".."z" | |
(5..35).to_a | |
1...10 | |
# ARRAYs | |
[] | |
[1, 2, 3, 123123] #=> integers | |
["alex", "cesar", "tegan"] #=> strings | |
[1, "alex", 3.14, [-1]] | |
[1,2,3,4,5].length #=> 5 | |
# [1,2,3,4,5].size | |
# [1,2,3,4,5].count | |
["d", "a", "z", "e", "b"].sort | |
["alex", "cesar", "tegan"] | |
# 0 1 2 | |
# VARIABLES | |
city = "Berlin" #=> assigning city Berlin to city | |
# puts city | |
city = "Tokyo" #=> reassigning city Tokyo to city | |
# puts city | |
city.upcase! #=> destructive | |
# age = 17 | |
# puts "You are #{age} years old" | |
# puts "Lucky you, it's your birthday!" | |
# age = age + 1 | |
# # age += 1 | |
# puts "You are now #{age}" | |
first_name = "Seb" | |
last_name = "Saunier" | |
full_name = "#{first_name} #{last_name}" | |
# full_name = first_name + " " + last_name | |
# puts full_name | |
# METHODS | |
def print_pretty_name | |
"Alex Haumer" | |
end | |
def tomorrow | |
tomorrow_date = Date.today + 1 | |
return tomorrow_date.strftime("%B %d") | |
end | |
# puts tomorrow | |
# puts print_pretty_name | |
def dynamic_print_full_name(first_name, last_name) | |
"#{first_name.capitalize} #{last_name.capitalize}" | |
end | |
# puts dynamic_print_full_name("ben", "baranger") | |
# full_name = dynamic_print_full_name("ben", "baranger") | |
# puts full_name | |
# def circle_area(radius) | |
# if radius.negative? | |
# # did stuff | |
# else | |
# # other stuff | |
# end | |
# end | |
def say_hi(name) | |
return "Hi #{name}." | |
end | |
# puts say_hi("Alex") # => "Hi Alex." | |
# puts say_hi("Edward") # => "Hi Edward." | |
# def some_method_name | |
# puts "above return" | |
# return | |
# puts "below return" | |
# end | |
# some_method_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment