forked from PilgrimMemoirs/classes_hashes_and_you_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashes_classes_and_you_demo.rb
55 lines (31 loc) · 1.18 KB
/
hashes_classes_and_you_demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#### HASHES, CLASSES & YOU ####
### Hash review:
people = [
{ name: "Jamie", email: "jamie@adadevelopersacademy.org" },
{ name: "Chris", email: "chris@adadevelopersacademy.org" }
]
#A hash has key value pairs. Often the keys are symbols, values can be any type
jamie = { jamie: # this is the key
# this entire hash is the value
{ last_name: "Pilgrim",
first_name: "Jamie",
address: {
street: "123 fake st",
city: "Seattle",
state: "WA"
},
pets: [
{ name: "Amper",
species: "tabby cat"
},
{ name: "Octo",
species: "mini puma"
}
]
}
}
#How do I find the name's of Jamie's pets?
### Let's setup an Address class
### Let's refactor the Address class to accept a hash as parameters instead
### Why do it this way?
### More Practice: Setup a person class that also takes in a hash argument. That hash argument should have at least one address that is an Address object.