-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby-intro-christian-nate.rb
140 lines (122 loc) · 3.23 KB
/
ruby-intro-christian-nate.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# IRB console challenges
# ➜ ruby-challenges git:(ruby-intro-cm-nr) ✗ irb
# 3.0.0 :001 > exit
# ➜ ruby-challenges git:(ruby-intro-cm-nr) ✗ irb
# 3.0.0 :001 > 2+2
# => 4
# 3.0.0 :002 > 2-1
# => 1
# 3.0.0 :003 > 3*3
# => 9
# 3.0.0 :004 > 4/2
# => 2
# 3.0.0 :005 > 2.0+3
# => 5.0
# 3.0.0 :006 > 3.0-2
# => 1.0
# 3.0.0 :007 > 3.2-2
# => 1.2000000000000002
# 3.0.0 :008 > 5.5*10
# => 55.0
# 3.0.0 :009 > 4.2/3
# => 1.4000000000000001
# 3.0.0 :010 > 4 % 2
# => 0
# 3.0.0 :011 > 10 % 2
# => 0
# 3.0.0 :012 > 5/0
# (irb):12:in `/': divided by 0 (ZeroDivisionError)
# from (irb):12:in `<main>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `load'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `<main>'
# 3.0.0 :013 > 5 %3
# => 2
# 3.0.0 :014 > 6 % 2
# => 0
# 3.0.0 :015 > 5 %2
# => 1
# 3.0.0 :016 > 10 %2
# => 0
# 3.0.0 :017 > 5 % 3
# => 2
# 3.0.0 :018 > 5/0
# (irb):18:in `/': divided by 0 (ZeroDivisionError)
# from (irb):18:in `<main>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `load'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `<main>'
# 3.0.0 :019 > 5.2 / 0
# => Infinity
# 3.0.0 :020 > 0/0
# (irb):20:in `/': divided by 0 (ZeroDivisionError)
# from (irb):20:in `<main>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `load'
# from /Users/learnacademy/.rvm/gems/ruby-3.0.0/bin/irb:23:in `<main>'
# 3.0.0 :021 > test = 2
# => 2
# 3.0.0 :022 > test
# => 2
# 3.0.0 :023 > test % 2
# => 0
# 3.0.0 :024 > test / 2
# => 1
# 3.0.0 :025 > test / 3
# => 0
# 3.0.0 :026 > test / 3.0
# => 0.6666666666666666
# 3.0.0 :027 > test2 = 13
# => 13
# 3.0.0 :028 > test > test2
# => false
# 3.0.0 :029 > test < test2
# => true
# 3.0.0 :030 > test = 7
# => 7
# 3.0.0 :031 > test
# => 7
# 3.0.0 :032 > test = *26
# => [26]
# 3.0.0 :033 > test
# => [26]
# 3.0.0 :034 > test = 7
# => 7
# 3.0.0 :035 > 7*26
# => 182
# 3.0.0 :036 > test = 182
# => 182
# 3.0.0 :037 >
new_word = 'hello'
puts "#{new_word} hows it goin"
# output: hello hows it goin
puts new_word.upcase
# output: HELLO
puts new_word.reverse
# output: olleh
puts new_word.include?('s')
# output: false
puts new_word.capitalize
# output: Hello
puts new_word.delete('l')
# output: heo
puts new_word.index('h')
# output: 0
puts new_word.swapcase
# output: HELLO
tv_shows = ['Psych', 'House of the Dragon', 'Atlanta', 'Bleach', 'Attack on Titan']
p tv_shows
# output: ['Psych', 'House of the Dragon', 'Atlanta', 'Bleach', 'Attack on Titan']
p tv_shows.length
# output: 5
p tv_shows.first
# output: "Psych"
p tv_shows[3]
# output: "Bleach"
p tv_shows.reverse!
# output: ["Attack on Titan", "Bleach", "Atlanta", "House of the Dragon", "Psych",]
new_tv_shows = []
# p new_tv_shows
# output: []
p new_tv_shows << tv_shows[4] << tv_shows[3]
# output: ["Psych", "House of the Dragon"]