Sign up or Sign in | Share
 
ClearMyBench
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Ruby basics (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Ruby basics
#4487
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Ranges occur everywhere: January to December, 0 to 9, lines 50 through 67, and so on.

Ruby supports ranges and allows us to use ranges in a variety of ways:

Ranges as Sequences

Ranges as Conditions

Ranges as Intervals
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4488
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
The first and perhaps most natural use of ranges is to express a sequence.

Sequences have a start point, an end point, and a way to produce successive values in the sequence
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4489
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Ruby creates these sequences using the ''..'' and ''...'' range operators.

The two-dot form creates an inclusive range, while the three-dot form creates a range that excludes the specified high value.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4490
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
The sequence 1..100 is held as a Range object containing references to two Fixnum objects.

If we need we can convert a range to a list using the to_a method
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4491
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Ranges as Intervals

A final use of the versatile range is as an interval test: seeing if some value falls within the interval represented by the range.

This is done using ===, the case equality operator
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4492
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Ranges as Conditions

Ranges may also be used as conditional expressions.

Ranges implement methods that let us to iterate over them and test their contents in a variety of ways
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
get the latest posts directly to your desktop
logo footer   Copyright 2009 - 2013 HotRecruiter.Com - All Rights Reserved