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
Copy file name to clipboardExpand all lines: source/articles/2015-01-05-what-i-left-out.html.markdown
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,18 @@
2
2
title: What I've left out
3
3
date: 2015/01/05
4
4
author: Ivo Herweijer
5
-
the_summary: TryRuby is a Ruby course for beginners. Its not possible to tell you everything about Ruby in 15 minutes. Here is an overview of what I have left out.
5
+
the_summary: TryRuby is a Ruby course for beginners. It's not possible to tell you everything about Ruby in 15 minutes. Here is an overview of what I have left out.
6
6
---
7
7
8
8
9
9
## What I've left out
10
10
11
-
TryRuby is a Ruby course for beginners. Its not possible to tell you everything about Ruby in
11
+
TryRuby is a Ruby course for beginners. It's not possible to tell you everything about Ruby in
12
12
30 minutes. Here is an overview of some of the things that I have left out.
13
13
14
14
### Comments
15
-
To add text to your Ruby file, you can do so with comments. Comments can be used for
16
-
documentation, explain parts of your code or anything else you'd like.
15
+
To add text to your Ruby file, you can use comments. Comments can be used for
16
+
documentation, to explain parts of your code, or anything else you'd like.
17
17
18
18
Single line comments
19
19
@@ -71,20 +71,20 @@ And there is an alternate form:
71
71
end
72
72
73
73
### Regular expressions
74
-
Sometimes you have a string and you want to test if that string contains some text. For instance if
74
+
Sometimes you have a string and you want to test whether it contains some text. For instance, whether
75
75
'user\_123' starts with 'user\_'. You could use a test like __my_string[0..4] == 'user\_'__, but
76
76
there is a much more elegant and flexible way to do this kind of string testing, called
77
77
regular expressions.
78
78
79
-
Reason this isn't in TryRuby lessons is the fact that regular expressions have a syntax that is so
79
+
The reason this isn't in the TryRuby lessons is that regular expressions have a syntax that is so
80
80
strange at first, it might make your head explode. If you see a complex regular expression for the
81
81
first time, it is like a monkey has been randomly bashing away on a keyboard.
82
82
83
83
The regex for the example mentioned above is relatively simple:
84
84
85
85
my_string.match( /^user_(\d+)/ )
86
86
87
-
This will return __nil__ if my_string didn't conform to the regex, or a matchdata object if it did.
87
+
This will return __nil__ if my_string didn't conform to the regex, or a MatchData object if it did.
88
88
In the last case it will also give you the 123 part as the matched data.
89
89
90
90
The Ruby <ahref="http://www.ruby-doc.org/core/Regexp.html"target="_blank">documentation</a> has
@@ -100,8 +100,8 @@ Now you can handle the missing method as if it existed. For instance you might w
100
100
a _sort\_by\_variable_ method. Where _variable_ is the name of one of your class variables.
101
101
102
102
### Inspection
103
-
Ruby can give you a lot of information about objects when a program is running. What an object is and
104
-
what methods it responds to.
103
+
Ruby can give you a lot of information about objects when a program is running, including what an object is
104
+
and what methods it responds to.
105
105
106
106
# Inspection
107
107
s = 'abc'
@@ -110,9 +110,9 @@ what methods it responds to.
110
110
puts s.respond_to?(:match)
111
111
112
112
### Error handling
113
-
Reality is that all programs can run into errors. Errors that only raise their ugly heads when your
113
+
The reality is that all programs can run into errors. Errors that only raise their ugly heads when your
114
114
program is running. And even when your code is flawless. That just happens.
115
-
You can let your program crash, but it is usually nicer if you let your program continue and politely tell
115
+
You can let your program crash, but it is usually nicer to let your program continue and politely report
116
116
that an error has occurred and it can't continue what it was doing.
117
117
Ruby has a couple of facilities for this purpose:
118
118
@@ -130,7 +130,7 @@ stupid).
130
130
raise "Yo dude seriously ? You can't enter zero for a divisor" if divisor == 0
131
131
132
132
### IO
133
-
You will often need to read or write diskfiles. That is easy in Ruby. For instance reading can be done with
133
+
You will often need to read or write disk files. That is easy in Ruby. For instance, reading can be done with
0 commit comments