SlideShare a Scribd company logo
RUBY ARRAY &
HASH
Hoang Quan(BlazingRockStorm)
Array
Contents
CONCEPT
ACCESSING ARRAY
ARRAY MANIPULATION
CREATING ARRAY
GET INFORMATION ABOUT AN ARRAY
INTERATING OVER ARRAY
OTHER METHODS
Concept
Concept
Arrays are ordered collections of objects,
integer-indexed
Array class inherits Object class and
includes Enumerable module
Array indexing starts at 0
A negative index is assumed to be
relative to the end of the array
Creating array
Creating
array
Accessing array
06. Ruby Array & Hash - Ruby Core Teaching
Get information about an
array
Get information about an array
Array manipulation
Array manipulation: Adding
Adding items to array by using either push or <<
Array manipulation: Adding
unshift will add new item to the beginning of an array
With insert you can add a new element to an array at any position
Array manipulation: flatten
Returns a new array that is a one-dimensional flattening of self
(recursively)
Array manipulation: flatten
Returns a new array that is a one-dimensional flattening of self
(recursively)
Array manipulation: Removing
The method pop removes the last element in an array and returns it
Array manipulation: Removing
To retrieve and at the same time remove the first item, use shift
To delete an element at a particular index
Interating over array
Interating over array
Array has each method, which includes from Enumerable module
Sometimes useful iterator is reverse_each which will iterate over the
elements in the array in reverse order
Interating over array
The map method can be used to create a new array based on the
original array
Other methods
Other methods
compact
concat
index
count
sample
select
shuffle
uniq
Hash
Contents
CONCEPT
ACCESSING HASH
ELEMENT ASIGNMENT
CREATING HASH
CONVERTING TO HASH
EQUALITY HASHES
INTERATING OVER HASH
OTHER METHODS
Concept
Concept
A Hash is a collection of key-value pairs
It is similar to an Array, except that
indexing is done via arbitrary keys of any
object type, not an integer index
Hashes enumerate their values in the
order that the corresponding keys were
inserted
Hashes have a default value that is
returned when accessing keys that do not
exist in the hash. By default, that value is
nil
Creating hash
Creating hash
Accessing array
Accessing
hash
Converting to hash
Converting to
hash
Using try_convert(obj) return
hash or nil
Equality hashes
Equality hashes
Operator: ==, >, <, >=, <= ⇒ return true/false
Element assignment
Element assignment
Interating over hash
Interating over hash
The map method can be used to create a new array based on the
original array
Other methods
Other methods
compact (!)
any?
empty?
include?
length
merge (!)
has_key?
reject (!)
size
shift
has_value?
select (!)
Thank you!
ありがとうございます!

More Related Content

Similar to 06. Ruby Array & Hash - Ruby Core Teaching (20)

Hashing data structure in genaral ss.ppt
Hashing data structure in genaral ss.ppt
ssusere3b1a2
 
15 ruby arrays
15 ruby arrays
Walker Maidana
 
18 hashing
18 hashing
deonnash
 
Java Collections.pptx
Java Collections.pptx
AbhishekKudal2
 
Hashing data
Hashing data
umair khan
 
Java Collections Framework
Java Collections Framework
Sony India Software Center
 
Array list(1)
Array list(1)
abdullah619
 
Ppt lesson 12
Ppt lesson 12
Linda Bodrie
 
Java Presentation
Java Presentation
mdfkhan625
 
Ch17 Hashing
Ch17 Hashing
leminhvuong
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptx
skilljiolms
 
java I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
adinathassociates
 
C# Collection classes
C# Collection classes
MohitKumar1985
 
Array properties
Array properties
Shravan Sharma
 
linear probing
linear probing
rajshreemuthiah
 
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
AbdisamedAdam
 
Collections Api - Java
Collections Api - Java
Drishti Bhalla
 
Java.util
Java.util
Ramakrishna kapa
 
Hashing
Hashing
LavanyaJ28
 
Java arrays (1)
Java arrays (1)
Liza Abello
 
Hashing data structure in genaral ss.ppt
Hashing data structure in genaral ss.ppt
ssusere3b1a2
 
18 hashing
18 hashing
deonnash
 
Java Presentation
Java Presentation
mdfkhan625
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptx
skilljiolms
 
java I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
adinathassociates
 
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
AbdisamedAdam
 
Collections Api - Java
Collections Api - Java
Drishti Bhalla
 

More from quanhoangd129 (8)

01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching
quanhoangd129
 
09. Ruby Object Oriented Programming - Ruby Core Teaching
09. Ruby Object Oriented Programming - Ruby Core Teaching
quanhoangd129
 
07. Ruby String Slides - Ruby Core Teaching
07. Ruby String Slides - Ruby Core Teaching
quanhoangd129
 
03. Ruby Variables & Regex - Ruby Core Teaching
03. Ruby Variables & Regex - Ruby Core Teaching
quanhoangd129
 
02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching
quanhoangd129
 
05. Ruby Control Structures - Ruby Core Teaching
05. Ruby Control Structures - Ruby Core Teaching
quanhoangd129
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
08. Ruby Enumerable - Ruby Core Teaching
08. Ruby Enumerable - Ruby Core Teaching
quanhoangd129
 
01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching
quanhoangd129
 
09. Ruby Object Oriented Programming - Ruby Core Teaching
09. Ruby Object Oriented Programming - Ruby Core Teaching
quanhoangd129
 
07. Ruby String Slides - Ruby Core Teaching
07. Ruby String Slides - Ruby Core Teaching
quanhoangd129
 
03. Ruby Variables & Regex - Ruby Core Teaching
03. Ruby Variables & Regex - Ruby Core Teaching
quanhoangd129
 
02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching
quanhoangd129
 
05. Ruby Control Structures - Ruby Core Teaching
05. Ruby Control Structures - Ruby Core Teaching
quanhoangd129
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
08. Ruby Enumerable - Ruby Core Teaching
08. Ruby Enumerable - Ruby Core Teaching
quanhoangd129
 
Ad

Recently uploaded (20)

Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Ad

06. Ruby Array & Hash - Ruby Core Teaching