Skip to content

Instantly share code, notes, and snippets.

@arthur-littm
Created October 6, 2017 09:19
Show Gist options
  • Save arthur-littm/5fce3194b4f53e76ce9b56efad073095 to your computer and use it in GitHub Desktop.
Save arthur-littm/5fce3194b4f53e76ce9b56efad073095 to your computer and use it in GitHub Desktop.
students = [ "Peter", "Mary", "George", "Emma" ]
student_ages = [ 24 , 25 , 22 , 20 ]
# - Peter is X years old
students.each_with_index do |name, index|
age = student_ages[index]
puts "#{name} is #{age} years old"
end
require "csv"
CSV.foreach("cities.csv") do |elephant|
puts "#{elephant[0]} has #{elephant[1]} people, monument: #{elephant[2]}"
end
paris = {
"country" => "France",
"population" => 2211000
}
names = ["arthur", "alex"]
# CRUD
# Array:
# c: names << "Edward"
# u: names[1] = "Alex"
# r: names[0]
# d: names.delete_at(-1)
# Hash
# create / update:
paris['monument'] = "Eiffel Tower"
# key value
# read
paris['population']
# delete
paris.delete('population')
paris = {
country: "France",
population: 2211000,
star_monument: "Tour Eiffel",
}
# paris.each do |key, value|
# puts "#{key} is #{value}"
# end
# puts paris.has_key?('country')
p paris[:country ]
require "json"
require "open-uri"
# STRING = open(URL).read
# HASH = JSON.parse(string)
string = open('https://api.github.com/users/voxoff').read
hash = JSON.parse(string)
puts "#{hash["name"]}'s id is #{hash["id"]}"
ARRAY = [1,2,3]
def method(attr)
end
# <div class="container" id="menu" style="color: green"></div>
def tag(tag_name, content, attributes = {})
p attributes
partials = attributes.map do |key, value|
"#{key}=\"#{value}\""
end
html_attr = partials.join(" ")
"<#{tag_name} #{html_attr}>#{content}</#{tag_name}>"
end
puts tag("h1", "Hello world")
puts tag('div', "", {
class: "container",
id: "menu"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment