a =[1,'cat',3.14]
puts a[0]
puts "\n"
a[2] = nil
puts a
puts "\n"
a[5] = nil
puts a
puts "\n"
b = Array.[](1,2,3,4)
puts b
puts "\n"
c = Array[5,6,7,8]
puts c
puts "\n"
d = Array['w','x','y','z']
puts d
puts "\n"
a = [10,12,14,16,18]
puts a.delete_at(3)
puts"\n"
puts a
puts "pause"
puts a.delete_at(9)
puts "\n"
puts b = %w(spam spam bacon spam eggs ham spam)
puts "\n"
puts b.delete("spam")
puts "\n"
puts b
puts "\n"
x = [0, 2, 4, 6, 8, 10, 12, 14, 16]
puts a = x.slice!(2)
puts "\n"
puts x
puts "\n"
x = [0, 2, 4, 6, 8, 10, 12, 14, 16]
puts a = x.slice(2)
puts "\n"
puts x
puts "\n"
puts x.pop
puts "\n"
puts x.shift
puts "\n"
puts x
puts "\n"
puts x.clear
puts "\n"
puts x #印不出來
puts "\n"
friends = ["Melissa", "Jeff", "Ashley", "Rob"]
friends.each do |friend|
puts "I have a friend called " + friend
end
puts "\n"
friends.reverse_each do |friend|
puts "I have a friend called " + friend
end
puts "\n"
accumulator = []
[1, 2, 3].reverse_each { |x| accumulator
puts accumulator
puts "\n"
x = ["a", "b", "c", "d"]
puts a = x.length
puts b = x.size
puts "\n"
y = [1, 2, nil, nil, 3, 4]
puts c = y.size # 6
puts d = y.length # 6
puts e = y.nitems # 4
puts "\n"
words = ["the", "quick", "brown", "fox"]
puts list = words.sort
puts "\n"
puts words
puts "\n"
puts words.sort!
puts "\n"
puts words
puts "\n"
class Array3
def initialize
@store = [[[]]]
end
def[] a,b,c
if @store[a]==nil||
@store[a][b]==nil||
@store[a][b][c]==nil
return nil
else
return @store[a][b][c]
end
end
def [] = (a,b,c,x)
@store[a] = [[]] if @store[a]==nil
@store[a][b] = [] if @store[a][b]==nil
@store[a][b][c] = x
end
end
x = Array3.new
x[0,0,0]=5
x[0,0,1]=6
x[1,2,3]=99
- Nov 20 Thu 2008 16:06
20081120
close
全站熱搜
留言列表