KEMBAR78
Ruby Data Types and Data Structures | PDF
Ruby Data Types
and
Data Structures
Integer
• The basis for the two concrete classes that hold
whole numbers, Bignum and Fixnum.
Fixnum
• size is native machine word (minus 1 bit)
4,611,686,018,427,387,903
Bignum
useful methods
Iteration
Float
• 1.3
• 4.99
• 38345.34
• 1.0
Float Methods
number equality
Range
Strings
Symbols
• starts with :
• if it has spaces :”more tacos”
Symbols
Arrays
• group of values, they don't have to be the same
type
Array Creation
Define with [ ] and values
Or with a length and optionally a default value
Array Methods
Array Methods
Hash
• key , value pairs
• keys can be strings or symbols
Hash Creation
Two Ways to create a Hash
Hash Syntax
String keys need the fat arrow
Two forms of syntax when defining values
Hash Methods
Sets
Create two ways
require “set”
Set Operations
Union
Merge
Sorted Set
Comparator
Using Sorted Set
Output Sorted Set
Go Bears!

Ruby Data Types and Data Structures