generated from LEARNAcademy/ruby-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashes-irvin-xavier-leo.rb
83 lines (55 loc) · 2.02 KB
/
hashes-irvin-xavier-leo.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#Create a variable called my_info and assign it to an empty hash using the .new method. (Expected output: {})
#my_info = Hash.new
#p my_info
#Add the following key-value pairs one at a time to the my_info variable: name: "John", age: 30, city: "San Diego".
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 30
#my_info[:city] = "San Diego"
#p my_info
#Log the value associated with the name key from the my_info variable.
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 30
#my_info[:city] = "San Diego"
#p my_info[:name]
#Log the value associated with the city key from the my_info variable.
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 30
#my_info[:city] = "San Diego"
#p my_info[:city]
#Update the value associated with the age key in the my_info variable to 35.
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 30
#my_info[:city] = "San Diego"
#p my_info[:age] = 35
#Create the code that will calculate and log the number of key-value pairs in the my_info variable. (Expected output: 3)
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 35
#my_info[:city] = "San Diego"
#p my_info.length
#Create a custom method called exists that takes the my_info variable and a key as arguments. Return true if the key exists in the hash,
#otherwise, return false. Use the following method calls to test the functionality.
#def exists(hash, key)
#hash.key?(key.to.sym)
#p exists(my_info, 'name')
#p exists(my_info, 'enjoys')
#p exists(my_info, 'city')
#end
#Create a custom method called numeric that takes the my_info variable and returns a hash with only the key-value pairs where the value is numeric.
#def numeric(info)
#numeric_info = info.select { |_, value| value.is_a?(Numeric) }
#return numeric_info
#end
#numeric_values = numeric(my_info)
#puts numeric_values
#Remove the key age and its associated value from the my_info variable.
#my_info = Hash.new
#my_info[:name] = "John"
#my_info[:age] = 35
#my_info[:city] = "San Diego"
#my_info.delete(:age)
#p my_info