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
#4493
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  
Iterators are nothing but methods supported by collections.

Objects that store a group of data members are called collections. In Ruby, arrays and hashes can be termed collections.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4494
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  
Iterators return all the elements of a collection, one after the other.

We will be discussing two iterators here, each and collect.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4495
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 each Iterator:

The each iterator returns all the elements of an array or a hash
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4496
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 each iterator returns all the elements of an array or a hash.

Syntax:

collection.each do |variable|
code
end


Executes code for each element in collection. Here collection could be an array or a ruby hash.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4497
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  
We always associate the each iterator with a block. It returns each value of the array, one by one, to the block.

The value is stored in the variable i and then displayed on the screen.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4498
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 collect Iterator:

The collect iterator returns all the elements of a collection.

Syntax:

collection = collection.collect
 
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