You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 23, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+42-4Lines changed: 42 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,12 @@ user_input.gsub!(/s/,"th")
54
54
```
55
55
This replaces all 's' in the string to 'th'.
56
56
57
+
_.split_ method returns all words in a string as an array. If text is given as parameter, it will divide the string wherever it sees that bit of text. The test is called _delimiter_.
58
+
```ruby
59
+
words = text.split("")
60
+
```
61
+
_text_ is a string and _words_ is an array. Space is delimiter here.
62
+
57
63
## Comments
58
64
Single line comments are written with hash(#) in the start. Multi-line comments start with _=begin_ and end with _=end_ .
59
65
```ruby
@@ -109,9 +115,9 @@ jobNotDone = false
109
115
print'Good work!!'unless jobNotDone
110
116
```
111
117
112
-
**Relational, Assigment and Comparison Operators** are same as for other common languages: = == > >= < <= !=
113
-
**Logical and Boolean operators**: && || !
114
-
Complex expressions can be created using these operators: E.g. *(x && (y || w)) && z*
118
+
**Relational, Assigment and Comparison Operators** are same as for other common languages: = == > >= < <= != </br>
119
+
**Logical and Boolean operators**: && || !</br>
120
+
Complex expressions can be created using these operators: E.g. *(x && (y || w)) && z*</br>
115
121
Expressions in parentheses are always evaluated before anything outside parentheses.
116
122
117
123
## Loops and Iterators
@@ -157,4 +163,36 @@ loop do
157
163
breakif i >5
158
164
end
159
165
```
160
-
You have to give a condition inside the block which will be used to decide when to break the loop.
166
+
A condition is given inside the block which will be used to decide when to break the loop.
167
+
The __next__ keyword can be used to skip over certain steps in the loop.
168
+
```ruby
169
+
i =20
170
+
loopdo
171
+
i -=1
172
+
nextif i%2!=0
173
+
puts"#{i}"
174
+
breakif i <=0
175
+
end
176
+
```
177
+
This code snippet will print only even numbers from 18 to 0.
178
+
179
+
Arrays in Ruby are declared as:
180
+
```ruby
181
+
my_array = [1,2,3,4,5]
182
+
```
183
+
__.each__ method is more powerful iterator.
184
+
```ruby
185
+
array = [1,2,3,4,5]
186
+
array.each do |x|
187
+
x +=10
188
+
print"#{x}"
189
+
end
190
+
```
191
+
_do_ and _end_ keywords can be replaced by curly braces {}.
192
+
193
+
The __.times__ method is like a super compact for loop: it can perform a task on each item in an object a specified number of times.
0 commit comments