loading
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Arrays are the main collection in Ruby. They implement many methods that allow use when building all sorts of different data structures

rubyists = ['Matz', 'DHH', '_why', 'tenderlove', 'kytrinyx']
puts rubyists.class
puts rubyists

# Arrays can be mixed and loosely contain different types
rubyists[5] = 42

# Array can be indexed from the left and right or subarrayed by a Range
puts rubyists[0]
puts rubyists[-1]
puts rubyists[0..1]
puts (0..1).class

# Hashes are Ruby Hashmaps. They generally use symbols as keys
personal_info = {:name => 'Sean', :blogging_experience => 'novice'}
puts "#{personal_info[:name]} is a #{personal_info[:blogging_experience]} blogger"

# But what are symbols?
# Notice that each string has a different object_id
puts 'hi'.object_id
puts 'hi'.object_id
puts 'hi'.object_id

# Each symbol has the same object_id
puts :hi.object_id
puts :hi.object_id
puts :hi.object_id
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]