Next 3.0 [Built-in types] Arrays/Hashes Prev

Arrays

a = [8, "Ruby", 95]
p a, a.class

p a[0, 2].reverse
p a.size                       # or: a.length
a.each {|i| print i * 2, "; "}
[8, "Ruby", 95]
Array

["Ruby", 8]
3
16; RubyRuby; 190; 

Hashes

h = { 1 => 2, "Ruby" => "ok", true => false }
p h, h.class

p h["Ruby"]
p h.keys
h.each {|key, val| print key, "-", val, " "}
{true=>false, 1=>2, "Ruby"=>"ok"}
Hash

"ok"
[true, 1, "Ruby"]
true-false 1-2 Ruby-ok 

Next Ruby for Perl programmers Prev