Реклама

Ruby – Back to the simple examples

Now let’s take apart the code of some of our previous example programs. The following appeared in the simple examples chapter. Because this is the first explanation, we examine each line individually. Factorials In the first line, def is a statement to define a function (or, more precisely, a method; we’ll talk more about what a method…

Ruby – Regular expressions

Let’s put together a more interesting program. This time we test whether a string fits a description, encoded into a concise pattern. There are some characters and character combinations that have special meaning in these patterns, including: [] – range specificication (e.g., [a-z] means a letter in the range a to z) \w – letter or…
Advertisement