forked from makersacademy/learn_to_program
-
Notifications
You must be signed in to change notification settings - Fork 0
/
learn2program_ch12.rb
57 lines (48 loc) · 1.04 KB
/
learn2program_ch12.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
=begin
#outputs include +#### at the end to account for GMT(UTC) difference
puts Time.new
puts Time.new + 60
puts Time.local(1988,3,11,1,12)
puts Time.local(2000,1,1)
#ignore time difference and use GMT(UTC) time
puts Time.gm(2000,1,1)
#comparing times
time1 = Time.gm(2000,1,1)
time2 = Time.gm(1999,12,31)
if time1 < time2
puts "#{time1} happened before #{time2}"
else
puts "#{time2} happened before #{time1}"
end
=end
=begin
#Hashes
dict_array = []
dict_hash = {}
dict_array[0] = 'candle'
dict_array[1] = 'glasses'
dict_array[2] = 'truck'
dict_array[3] = 'Alicia'
dict_hash['shia-a'] = 'candle'
dict_hash['shaya'] = 'glasses'
dict_hash['shasha'] = 'truck'
dict_hash['sh-sha'] = 'Alicia'
dict_array.each do |word|
puts word
end
dict_hash.each do |c_word, word|
puts "#{c_word}: #{word}"
end
=end
=begin
#Ranges
letters = 'a'..'c' #letters contain a-c
print letters.to_a #convert 'letters' var to an array and print array
puts
puts(['a','b','c'] == letters.to_a)
#iterate over ranges
('A'..'Z').each do |letter|
print letter
end
puts
=end