Created
October 6, 2017 09:19
-
-
Save arthur-littm/5fce3194b4f53e76ce9b56efad073095 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
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 | |
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 "csv" | |
CSV.foreach("cities.csv") do |elephant| | |
puts "#{elephant[0]} has #{elephant[1]} people, monument: #{elephant[2]}" | |
end |
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
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') |
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
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 ] | |
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 "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 |
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
# <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