Home arrow Ruby-on-Rails arrow Page 4 - Ruby Operators and Arrays
RUBY-ON-RAILS

Ruby Operators and Arrays


You've heard the phrase “diamonds are a girl's best friend”? Well, rubies are a nerd's best friend, and in this tutorial I am going to show you why. We'll discuss operators, conditionals, loops, hashes, and arrays in Ruby. And that's not all.

Author Info:
By: James Payne
Rating: 4 stars4 stars4 stars4 stars4 stars / 5
October 16, 2007
TABLE OF CONTENTS:
  1. · Ruby Operators and Arrays
  2. · Running for Precedence
  3. · Hashes
  4. · Home on the Range

print this article
SEARCH DEVARTICLES

Ruby Operators and Arrays - Home on the Range
(Page 4 of 4 )

I wonder exactly how buffalo play. And what. Maybe when no one is looking they pull up an old log, light up a hickory pipe, and play a good game of chess, huffing and blowing smoke and mutter pip pip, cheerio a lot.

Ranges in Ruby don't have buffalo on them (well I guess they could if you really wanted). They allow you to work with a set of items. For instance, January through December would be a range. A group of numbers would also be a range, as shown below.


your_range = 1..10

puts your_range

This would print out the following:

 

  1

  2

  3

  4

etc. You can also use the ... operator, which simply omits the final value:


your_range = 1...10

puts your_range

Would print the values 1 through nine only. We'll get more into ranges in the next tutorial.

That's right, I tricked you. Here you thought we would be doing Conditionals and Loops and all kinds of crazy statements. Well you were wrong. It was just a brilliant trick to get you to read the next tutorial (well that and I ran past my word limit). So stick with me and read the next tutorial, where we will get down and dirty with Ruby.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials