-
Notifications
You must be signed in to change notification settings - Fork 0
Array Methods In Ruby
richlewis14 edited this page Nov 5, 2012
·
2 revisions
Here are some Array methods in Ruby with examples
Array used for this example will be
a = ["first", "second", "third", "fourth", "fifth"]
.empty? True if the array is empty
a.empty?
.first The first value in the array
a.first
**.include? ** True if the array includes the given value
a.include?("first")
.index The index number of a given value
a.index("fourth")
.inspect The array in a printable format
a.inspect
.last The last value in the array
a.last
.length The number of items in the array
a.length
.reverse The array in reverse order
a.reverse
.sort The array sorted
a.sort
.uniq The unique values in the array
a.uniq