-
Notifications
You must be signed in to change notification settings - Fork 2
Array
Douglas G. Allen edited this page Feb 1, 2015
·
7 revisions
http://www.ruby-doc.org/core-2.2.0/Array.html http://www.rubyist.net/~slagell/ruby/arrays.html http://www.techotopia.com/index.php/Understanding_Ruby_Arrays http://www.techotopia.com/index.php/Advanced_Ruby_Arrays
procs = []
#=> []
procs[1] = "Procs"
#=> "Procs"
procs[2] = "Blocks"
#=> "Blocks"
procs[3] = "Lambdas"
#=> "Lambdas"
procs.each {|ae| puts ae }
#=> Procs
#=> Blocks
#=> Lambdas
#=> [nil, "Procs", "Blocks", "Lambdas"]
procs[4] = nil
#=> nil
procs
#=> [nil, "Procs", "Blocks", "Lambdas", nil]
######################################################
# Array to Hash
my_dazzling_array = [2, 5, 6, 7, 8, 9, 10, 15, 16, 17, 14, 20, 21]
ei = Hash.new()
my_dazzling_array.each_with_index {|e, i| ei[i] = e}
ei # => {0=>2, 1=>5, 2=>6, 3=>7, 4=>8, 5=>9, 6=>10, 7=>15, 8=>16, 9=>17, 10=>14, 11=>20, 12=>21}
# Hash to Array
ei.values
# => [2, 5, 6, 7, 8, 9, 10, 15, 16, 17, 14, 20, 21]