|
1 | 1 | ---
|
2 | 2 | layout: page
|
3 |
| -title: About Ruby |
| 3 | +title: "About Ruby" |
4 | 4 | lang: en
|
5 | 5 | ---
|
6 | 6 |
|
7 |
| -Wondering why Ruby is so popular? Its fans call it a beautiful, |
8 |
| -artful language. And yet, they say it's handy and practical. |
9 |
| -What gives? |
| 7 | +Wondering why Ruby is so popular? Its fans call it a beautiful, artful |
| 8 | +language. And yet, they say it’s handy and practical. What gives? |
10 | 9 |
|
11 |
| -### The Ideals of Ruby's Creator |
| 10 | +### The Ideals of Ruby’s Creator |
12 | 11 |
|
13 |
| -<p style="float:right"><img src="http://redhanded.hobix.com/images/ruby-lang-matz.png" style="padding-left:8px;" alt=""></p> |
| 12 | +{: |
| 13 | +style="padding-left:8px;"} |
| 14 | +{: style="float:right"} |
14 | 15 |
|
15 |
| -Ruby is a language of careful balance. Its creator, |
16 |
| -[Yukihiro "matz" Matsumoto](http://www.rubyist.net/~matz/), blended parts |
17 |
| -of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form |
18 |
| -a new language that balanced functional programming with imperative |
19 |
| -programming. |
| 16 | +Ruby is a language of careful balance. Its creator, [Yukihiro “matz” |
| 17 | +Matsumoto][1], blended parts of his favorite languages (Perl, Smalltalk, |
| 18 | +Eiffel, Ada, and Lisp) to form a new language that balanced functional |
| 19 | +programming with imperative programming. |
20 | 20 |
|
21 |
| -He has often said that he is "trying to make Ruby natural, not simple," |
| 21 | +He has often said that he is “trying to make Ruby natural, not simple,” |
22 | 22 | in a way that mirrors life.
|
23 | 23 |
|
24 | 24 | Building on this, he adds:
|
25 | 25 |
|
26 | 26 | > Ruby is simple in appearance, but is very complex inside, just like
|
27 |
| -> our human body <sup markdown="true">[1](#fn1)</sup>. |
| 27 | +> our human body<sup>[1](#fn1)</sup>. |
28 | 28 |
|
29 |
| -### About Ruby's Growth |
| 29 | +### About Ruby’s Growth |
30 | 30 |
|
31 |
| -Since its public release in 1995, Ruby has drawn devoted coders worldwide. |
32 |
| -In 2006, Ruby achieved mass acceptance. With active user groups formed in |
33 |
| -the world's major cities and Ruby-related conferences filled to capacity. |
| 31 | +Since its public release in 1995, Ruby has drawn devoted coders |
| 32 | +worldwide. In 2006, Ruby achieved mass acceptance. With active user |
| 33 | +groups formed in the world’s major cities and Ruby-related conferences |
| 34 | +filled to capacity. |
34 | 35 |
|
35 |
| -<p style="float:right"><img src="http://gmane.org/plot-rate.php?group=gmane.comp.lang.ruby.general&width=280&height=140&title=Ruby-Talk+Activity" style="padding-left:8px;" title="Graph courtesy of Gmane." alt="Graph courtesy of Gmane."></p> |
| 36 | +{: style="padding-left:8px;"} |
| 39 | +{: style="float:right"} |
36 | 40 |
|
37 | 41 | Ruby-Talk, the primary [mailing list](/en/community/mailing-lists/) for
|
38 |
| -discussion of the Ruby language, climbed to an average of 200 messages per |
39 |
| -day in 2006. It has dropped in recent years as the size of the community |
40 |
| -pushed discussion from one central list into many smaller groups. |
| 42 | +discussion of the Ruby language, climbed to an average of 200 messages |
| 43 | +per day in 2006. It has dropped in recent years as the size of the |
| 44 | +community pushed discussion from one central list into many smaller |
| 45 | +groups. |
41 | 46 |
|
42 | 47 | The TIOBE index, which measures the growth of programming languages,
|
43 |
| -ranks Ruby as #9 among programming languages worldwide. Much of the growth |
44 |
| -is attributed to the popularity of software written in Ruby, particularly |
45 |
| -the Ruby on Rails web framework <sup markdown="true">[2](#fn2)</sup>. |
| 48 | +ranks Ruby as #9 among programming languages worldwide. Much of the |
| 49 | +growth is attributed to the popularity of software written in Ruby, |
| 50 | +particularly the Ruby on Rails web framework<sup>[2](#fn2)</sup>. |
46 | 51 |
|
47 |
| - |
48 |
| -Ruby is also [totally free](/license.txt). Not only free of charge, but |
| 52 | +Ruby is also [totally free](./license.txt). Not only free of charge, but |
49 | 53 | also free to use, copy, modify, and distribute.
|
50 | 54 |
|
51 | 55 | ### Seeing Everything as an Object
|
52 | 56 |
|
53 |
| - |
54 | 57 | Initially, Matz looked at other languages to find an ideal syntax.
|
55 |
| -Recalling his search, he said, "I wanted a scripting language that was more |
56 |
| -powerful than Perl, and more object-oriented than Python |
57 |
| -<sup markdown="true">[1](#fn3)</sup>." |
58 |
| - |
59 |
| - |
60 |
| -In Ruby, everything is an object. Every bit of information and code can be |
61 |
| -given their own properties and actions. Object-oriented programming calls |
62 |
| -properties by the name _instance variables_ and actions are known as |
63 |
| -_methods_. Ruby's pure object-oriented approach is most commonly |
| 58 | +Recalling his search, he said, “I wanted a scripting language that was |
| 59 | +more powerful than Perl, and more object-oriented than |
| 60 | +Python<sup>[3](#fn3)</sup>.” |
| 61 | + |
| 62 | +In Ruby, everything is an object. Every bit of information and code can |
| 63 | +be given their own properties and actions. Object-oriented programming |
| 64 | +calls properties by the name *instance variables* and actions are known |
| 65 | +as *methods*. Ruby’s pure object-oriented approach is most commonly |
64 | 66 | demonstrated by a bit of code which applies an action to a number.
|
65 | 67 |
|
66 |
| - {% highlight ruby %} |
67 | 68 | 5.times { print "We *love* Ruby -- it's outrageous!" }
|
68 |
| - {% endhighlight %} |
| 69 | +{: .code .ruby-code} |
69 | 70 |
|
70 |
| -### Ruby's Flexibility |
| 71 | +In many languages, numbers and other primitive types are not objects. |
| 72 | +Ruby follows the influence of the Smalltalk language by giving methods |
| 73 | +and instance variables to all of its types. This eases one’s use of |
| 74 | +Ruby, since rules applying to objects apply to all of Ruby. |
| 75 | + |
| 76 | +### Ruby’s Flexibility |
71 | 77 |
|
72 | 78 | Ruby is seen as a flexible language, since it allows its users to freely
|
73 |
| -alter its parts. Essential parts of Ruby can be removed or redefined, |
74 |
| -at will. Existing parts can be added upon. Ruby tries not to restrict the |
| 79 | +alter its parts. Essential parts of Ruby can be removed or redefined, at |
| 80 | +will. Existing parts can be added upon. Ruby tries not to restrict the |
75 | 81 | coder.
|
76 | 82 |
|
77 |
| -For example, addition is performed with the plus (`+`) operator. But, |
78 |
| -if you'd rather use the readable word `plus`, you could add such a method to |
79 |
| -Ruby's builtin `Numeric` class. |
| 83 | +For example, addition is performed with the plus (`+`) operator. But, if |
| 84 | +you’d rather use the readable word `plus`, you could add such a method |
| 85 | +to Ruby’s builtin `Numeric` class. |
80 | 86 |
|
81 |
| - {% highlight ruby %} |
82 | 87 | class Numeric
|
83 |
| - def plus(x) |
84 |
| - self.+(x) |
85 |
| - end |
| 88 | + def plus(x) |
| 89 | + self.+(x) |
| 90 | + end |
86 | 91 | end
|
87 | 92 |
|
88 | 93 | y = 5.plus 6
|
89 | 94 | # y is now equal to 11
|
90 |
| - {% endhighlight %} |
| 95 | +{: .code .ruby-code} |
91 | 96 |
|
92 |
| -Ruby's operators are syntactic sugar for methods. You can redefine them as |
93 |
| -well. |
| 97 | +Ruby’s operators are syntactic sugar for methods. You can redefine them |
| 98 | +as well. |
94 | 99 |
|
95 | 100 | ### Blocks, a Truly Expressive Feature
|
96 | 101 |
|
97 |
| -Ruby's block are also seen as a source of great flexibility. A programmer |
98 |
| -can attach a closure to any method, describing how that method should act. |
99 |
| -The closure is called a _block_ and has become one of the most |
100 |
| -popular features for newcomers to Ruby from other imperative languages |
101 |
| -like PHP or Visual Basic. |
| 102 | +Ruby’s block are also seen as a source of great flexibility. A |
| 103 | +programmer can attach a closure to any method, describing how that |
| 104 | +method should act. The closure is called a *block* and has become one of |
| 105 | +the most popular features for newcomers to Ruby from other imperative |
| 106 | +languages like PHP or Visual Basic. |
102 | 107 |
|
103 |
| -Blocks are inspired by functional languages. Matz said, "in Ruby closures, |
104 |
| -I wanted to respect the Lisp culture <sup markdown="true">[4](#fn4)</sup>" |
| 108 | +Blocks are inspired by functional languages. Matz said, “in Ruby |
| 109 | +closures, I wanted to respect the Lisp culture<sup>[4](#fn4)</sup>.” |
105 | 110 |
|
106 |
| - {% highlight ruby %} |
107 |
| - search_engines = %w[Google Yahoo MSN].map do |engine| |
108 |
| - "http://www." + engine.downcase + ".com" |
109 |
| - end |
110 |
| - {% endhighlight %} |
| 111 | + search_engines = |
| 112 | + %w[Google Yahoo MSN].map do |engine| |
| 113 | + "http://www." + engine.downcase + ".com" |
| 114 | + end |
| 115 | +{: .code .ruby-code} |
111 | 116 |
|
112 | 117 | In the above code, the block is described inside the `do ... end`
|
113 |
| -construct. The `map` method applies the block to the provided list of words. |
114 |
| -Many other methods in Ruby leave a hole open for a coder to write their own |
115 |
| -block to fill in the details of what that method should do. |
| 118 | +construct. The `map` method applies the block to the provided list of |
| 119 | +words. Many other methods in Ruby leave a hole open for a coder to write |
| 120 | +their own block to fill in the details of what that method should do. |
116 | 121 |
|
117 | 122 | ### Ruby and the Mixin
|
118 | 123 |
|
119 | 124 | Unlike many object-oriented languages, Ruby features single inheritance
|
120 |
| -only, **on purpose**. But Ruby knows the concept of modules |
121 |
| -(called Categories in Objective-C). Modules are collections of methods. |
| 125 | +only, **on purpose**. But Ruby knows the concept of modules (called |
| 126 | +Categories in Objective-C). Modules are collections of methods. |
122 | 127 |
|
123 |
| -Classes can mixin a module and receive all its methods for free. |
124 |
| -For example, any class which implements the `each` method can mixin the |
| 128 | +Classes can mixin a module and receive all its methods for free. For |
| 129 | +example, any class which implements the `each` method can mixin the |
125 | 130 | `Enumerable` module, which adds a pile of methods that use `each` for
|
126 | 131 | looping.
|
127 | 132 |
|
128 |
| - {% highlight ruby %} |
129 | 133 | class MyArray
|
130 |
| - include Enumerable |
| 134 | + include Enumerable |
131 | 135 | end
|
132 |
| - {% endhighlight %} |
| 136 | +{: .code .ruby-code} |
133 | 137 |
|
134 | 138 | Generally, Rubyists see this as a much clearer way than multiple
|
135 | 139 | inheritance, which is complex and can be too restrictive.
|
136 | 140 |
|
137 |
| -### Ruby's Visual Appearance |
| 141 | +### Ruby’s Visual Appearance |
138 | 142 |
|
139 |
| -While Ruby often uses very limited punctuation and usually prefers English |
140 |
| -keywords, some punctuation is used to decorate Ruby. Ruby needs no variable |
141 |
| -declarations. It uses simple naming conventions to denote the scope of |
142 |
| -variables. |
| 143 | +While Ruby often uses very limited punctuation and usually prefers |
| 144 | +English keywords, some punctuation is used to decorate Ruby. Ruby needs |
| 145 | +no variable declarations. It uses simple naming conventions to denote |
| 146 | +the scope of variables. |
143 | 147 |
|
144 | 148 | * `var` could be a local variable.
|
145 | 149 | * `@var` is an instance variable.
|
146 | 150 | * `$var` is a global variable.
|
147 | 151 |
|
148 | 152 | These sigils enhance readability by allowing the programmer to easily
|
149 |
| -identify the roles of each variable. It also becomes unnecessary to use a |
150 |
| -tiresome `self.` prepended to every instance member. |
| 153 | +identify the roles of each variable. It also becomes unnecessary to use |
| 154 | +a tiresome `self.` prepended to every instance member. |
151 | 155 |
|
152 | 156 | ### Beyond the Basics
|
153 | 157 |
|
154 | 158 | Ruby has a wealth of other features, among which are the following:
|
155 | 159 |
|
156 |
| -* Ruby has exception handling features, like Java or Python, |
157 |
| - to make it easy to handle errors. |
| 160 | +* Ruby has exception handling features, like Java or Python, to make it |
| 161 | + easy to handle errors. |
| 162 | +^ |
| 163 | + |
158 | 164 | * Ruby features a true mark-and-sweep garbage collector for all Ruby
|
159 |
| - objects. No need to maintain reference counts in extension |
160 |
| - libraries. As Matz says, "This is better for your health." |
| 165 | + objects. No need to maintain reference counts in extension libraries. |
| 166 | + As Matz says, “This is better for your health.” |
| 167 | +^ |
| 168 | + |
161 | 169 | * Writing C extensions in Ruby is easier than in Perl or Python, with a
|
162 | 170 | very elegant API for calling Ruby from C. This includes calls for
|
163 |
| - embedding Ruby in software, for use as a scripting language. |
164 |
| - A SWIG interface is also available. |
| 171 | + embedding Ruby in software, for use as a scripting language. A SWIG |
| 172 | + interface is also available. |
| 173 | +^ |
| 174 | + |
165 | 175 | * Ruby can load extension libraries dynamically if an OS allows.
|
166 |
| -* Ruby features OS independent threading. Thus, for all platforms on which |
167 |
| - Ruby runs, you also have multithreading, regardless of if the OS supports |
168 |
| - it or not, even on MS-DOS! |
169 |
| -* Ruby is highly portable: it is developed mostly on GNU/Linux, |
170 |
| - but works on many types of UNIX, Mac OS X, Windows 95/98/Me/NT/2000/XP, |
| 176 | +^ |
| 177 | + |
| 178 | +* Ruby features OS independent threading. Thus, for all platforms on |
| 179 | + which Ruby runs, you also have multithreading, regardless of if the OS |
| 180 | + supports it or not, even on MS-DOS! |
| 181 | +^ |
| 182 | + |
| 183 | +* Ruby is highly portable: it is developed mostly on GNU/Linux, but |
| 184 | + works on many types of UNIX, Mac OS X, Windows 95/98/Me/NT/2000/XP, |
171 | 185 | DOS, BeOS, OS/2, etc.
|
172 | 186 |
|
173 | 187 | #### References
|
174 | 188 |
|
175 |
| -<p id="fn1"> |
176 |
| - <sup>1</sup> Matz, speaking on the Ruby-Talk mailing list, |
177 |
| - <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773">May 12th, 2000</a>. |
178 |
| -</p> |
| 189 | +<sup>1</sup> Matz, speaking on the Ruby-Talk mailing list, [May 12th, |
| 190 | +2000][2]. |
| 191 | +{: #fn1} |
| 192 | + |
| 193 | +<sup>2</sup> See the [Ruby on Rails][3] home page for more. |
| 194 | +{: #fn2} |
| 195 | + |
| 196 | +<sup>3</sup> Matz, in [An Interview with the Creator of Ruby][4], Nov. |
| 197 | +29th, 2001. |
| 198 | +{: #fn3} |
| 199 | + |
| 200 | +<sup>4</sup> Matz, in [Blocks and Closures in Ruby][5], December 22nd, |
| 201 | +2003. |
| 202 | +{: #fn4} |
179 | 203 |
|
180 |
| -<p id="fn2"> |
181 |
| - <sup>2</sup> See the <a href="http://rubyonrails.org/">Ruby on Rails</a> home page for more. |
182 |
| -</p> |
183 | 204 |
|
184 |
| -<p id="fn3"> |
185 |
| - <sup>3</sup> Matz, in <a href="http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html">An Interview with the Creator of Ruby</a>, Nov. 29th, 2001. |
186 |
| -</p> |
187 | 205 |
|
188 |
| -<p id="fn4"> |
189 |
| - <sup>4</sup> Matz, in <a href="http://www.artima.com/intv/closures2.html">Blocks and Closures in Ruby</a>, |
190 |
| - December 22nd, 2003. |
191 |
| -</p> |
| 206 | +[1]: http://www.rubyist.net/~matz/ |
| 207 | +[2]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773 |
| 208 | +[3]: http://rubyonrails.org/ |
| 209 | +[4]: http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html |
| 210 | +[5]: http://www.artima.com/intv/closures2.html |
0 commit comments