view · edit · sidebar · attach · print · history

Dealing with Arrays in Ruby

<< AliasMethodAlternative | Index | Ascii2Utf8 >>

 http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_array.html

some examples in

 http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_array.html

seem odd!

 http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Arrays

Set an array element inside a block:

a = []

p a[3]
a[3] ||= 123
p a[3]
a[3] ||= 456
p a[3]

if a[3] == nil
 a[3] = 789
end

0.upto 5 do |i|
 a[i] ||= i
end

p a

results in

nil
123
123
[0, 1, 2, 123, 4, 5]
view · edit · sidebar · attach · print · history
Page last modified on March 15, 2011, at 09:06 AM