Ruby Data Types and Data Structures

27
Ruby Data Types and Data Structures

Transcript of Ruby Data Types and Data Structures

Page 1: Ruby Data Types and Data Structures

Ruby Data Types and

Data Structures

Page 2: Ruby Data Types and Data Structures

Integer

• The basis for the two concrete classes that hold whole numbers, Bignum and Fixnum.

Page 3: Ruby Data Types and Data Structures

Fixnum• size is native machine word (minus 1 bit)

4,611,686,018,427,387,903

Page 4: Ruby Data Types and Data Structures

Bignum

Page 5: Ruby Data Types and Data Structures

useful methods

Page 6: Ruby Data Types and Data Structures

Iteration

Page 7: Ruby Data Types and Data Structures

Float

• 1.3

• 4.99

• 38345.34

• 1.0

Page 8: Ruby Data Types and Data Structures

Float Methods

Page 9: Ruby Data Types and Data Structures

number equality

Page 10: Ruby Data Types and Data Structures

Range

Page 11: Ruby Data Types and Data Structures

Strings

Page 12: Ruby Data Types and Data Structures

Symbols

• starts with :

• if it has spaces :”more tacos”

Page 13: Ruby Data Types and Data Structures

Symbols

Page 14: Ruby Data Types and Data Structures

Arrays• group of values, they don't have to be the same

type

Page 15: Ruby Data Types and Data Structures

Array CreationDefine with [ ] and values

Or with a length and optionally a default value

Page 16: Ruby Data Types and Data Structures

Array Methods

Page 17: Ruby Data Types and Data Structures

Array Methods

Page 18: Ruby Data Types and Data Structures

Hash

• key , value pairs

• keys can be strings or symbols

Page 19: Ruby Data Types and Data Structures

Hash CreationTwo Ways to create a Hash

Page 20: Ruby Data Types and Data Structures

Hash Syntax

String keys need the fat arrow

Two forms of syntax when defining values

Page 21: Ruby Data Types and Data Structures

Hash Methods

Page 22: Ruby Data Types and Data Structures

Sets

Create two ways

require “set”

Page 23: Ruby Data Types and Data Structures

Set OperationsUnion

Merge

Page 24: Ruby Data Types and Data Structures

Sorted Set

Page 25: Ruby Data Types and Data Structures

Comparator

Page 26: Ruby Data Types and Data Structures

Using Sorted Set

Page 27: Ruby Data Types and Data Structures

Output Sorted Set

Go Bears!