Home
Blog
Favorite Feature in Ruby Language
Updated
Dot Net Perls

Favorite Feature in Ruby Language

Ruby is a language similar to Python but with object-oriented design, and an emphasis on syntax that makes programs easier to read and write. It is an enjoyable language to use, although I have not written any large or serious programs with it.

Ruby has traditional loops like for and while, but I find the iterator syntax, and methods like times, upto, downto, step and each to be more elegant. The iterators can even reduce bugs by avoiding the need for indexing variables.

Iterators have many diverse benefits:

They read more like English, so we can say "zero upto ten" for a loop from zero to ten.
As noted, they can reduce bugs by giving us elements in an array, like with each, not an iteration variable into the array.
We can handle range checks in one place in the loop, and not worry about them elsewhere.

Although the iteration block syntax is difficult at first, it makes sense the longer you use it. And many simple iterators do not require block syntax at all—we can just use the do-keyword instead. Having used Ruby in some projects, I find iterators to be one of Ruby's best features.

Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
No updates found for this page.
Home
Changes
© 2007-2025 Sam Allen