Ruby Data Types and Data Structures
-
Upload
nola-stowe -
Category
Internet
-
view
172 -
download
1
Transcript of Ruby Data Types and Data Structures
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 CreationDefine 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 CreationTwo 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 OperationsUnion
Merge
Sorted Set
Comparator
Using Sorted Set
Output Sorted Set
Go Bears!