-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.rb
57 lines (35 loc) · 837 Bytes
/
arrays.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/ruby
a1 = [1,2,3,4,5]
arr = [nil,"first","Hello",2,"ruby",3,"last" , nil,3]
puts arr.at(0)
puts arr.fetch(3)
puts arr.last
puts arr.drop(3)
puts arr.take(3)
puts arr.include?('everyone')
puts arr.push(11)
puts arr << 12
puts arr.unshift(0)
puts arr.insert(3, 'orange', 'pear', 'grapefruit')
puts arr.pop
puts arr.shift
puts arr.delete(2)
puts arr.compact!
puts arr.uniq!
puts a1.map { |a| 2*a }
arr.each do |i|
puts "array elements #{i}"
end
ary = Array.new
Array.new(3)
puts Array.new(3, "hey")
puts Array({:a => "Good", :b => "Morning"})
#hash example
hsh = colors = { "red" => 0xf00, "green" => 0x0f0, "blue" => 0x00f }
hsh.each do |key, value|
print key, " is ", value, "\n"
end
#range
(10..15).each do |n|
print n, ' '
end