Created
July 15, 2016 02:38
-
-
Save arpit/135e93dea1b54fda56fe6bf529bcaf10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#create empty hash | |
myhash = {} | |
# or | |
myh = Hash.new | |
# keys no value | |
info = { :name => nil, :address => nil } | |
#set value of keu | |
info[:name] = "arpit" | |
# | |
info.each do |k,v| | |
puts "The key is #{k} and the value is #{v}" | |
end | |
# hashes in arrays | |
one = { :name => "arpit", :city => "philly" } | |
two = { :name => "dana", :city => "philly" } | |
three = { :name => "jack", :city => "new york" } | |
people = [one, two, three] | |
people.each do |c| | |
puts c[:city] | |
end | |
# array in hash | |
one[:hobbies] = [ "art", "movies", "music"] | |
# supermarket #of aisles abcd each has random products | |
#products are bread donuts cornflakes chocolate | |
products = ["bread", "dountes", "cornflakes", "chocolate"] | |
aisles = { "a" => [], "b" => [], "c" => [], "d" => [] } | |
products.each do |p| | |
aisles[ p[0] ] << p | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment