Skip to content

Instantly share code, notes, and snippets.

@arthur-littm
Created October 11, 2019 09:04
Show Gist options
  • Save arthur-littm/66a71743c1e7ba3bf6d2bf2fdf03abf0 to your computer and use it in GitHub Desktop.
Save arthur-littm/66a71743c1e7ba3bf6d2bf2fdf03abf0 to your computer and use it in GitHub Desktop.
cities = ["london", "paris", "berlin"]
# 0 1 2
# CREATE
# cities.push("olso")
cities << "madrid"
# READ
# p cities.last
p cities[3]
# UPDATE
cities[1] = "Marseille"
# DELETE
# cities.delete("london")
cities.delete_at(0)
# p cities
# HASHES
paris = {
country: "France",
population: 2230301
}
# CREATE
paris[:monument] = "Eiffel Tower"
# UPDATE
paris[:country] = "Italy"
# READ
paris[:population]
# DELETE
paris.delete("country")
paris.each do |key, value|
puts "the #{key} is #{value}"
end
# students = [ "Peter", "Mary", "George", "Emma" ]
# student_ages = [ 24 , 25 , 22 , 20 ]
# # 0 1 2 3
# # Peter is 24 years old
# # Mary is 25 years old
# # [...]
# students.each_with_index do |student, index|
# puts "#{student} is #{student_ages[index]} years old"
# end
students = {
"Peter" => 24,
"Mary" => 25,
"George" => 22
}
students.each do |student_name, student_age|
puts "#{student_name} is #{student_age} years old"
end
def tag(tag_name, content, attributes)
str = ""
attributes.each do |key, value|
str += " #{key}='#{value}'"
# key="value"
end
return "<#{tag_name}#{str}>#{content}</#{tag_name}>"
end
puts tag("h1", "Hello", {})
puts tag("div", "Hello", {class: "text-blue", id: "banner"})
# <h1>Hello</h1>
# <p class="text-blue">This is a paragraph</p>
# <div id="banner" class="text-center">Hello</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment