Things that aren’t obvious

In ruby, pretty much everything is an object. If you create an integer, say, 5, that’s an object. And there are methods that can be run on that object.

As an integer, 1 is an object in the “fixnum” class. You don’t have to tell this to ruby, it’s capable of figuring that out all on its own. This means you can do things to the number 1 using methods from the fixnum class, like this:

1.upto(10)

upto is a method in the fixnum class that repeats the code below it for the range of times between the number to the left of the dot and the number in parens. So:

1.upto(10)
   some_code_I_wrote

Will run some_code_I_wrote 10 times.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Skip to content