Skip to content

Commit

Permalink
removed some methods that array already has predefined (in some way)...
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Sep 3, 2008
1 parent fde5d28 commit 5d8347a
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/lib/array_enhancement.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
# small enhancements to array class
module ArrayEnhancement

# returns a new array with only the first amount elements.
def take(amount)
first_n = []

if amount > self.size
amount = self.size
end

amount.times do |n|
first_n << self[n]
end

first_n
end


# returns a new array with the first amount elements left out.
def skip(amount)
self - self.take(amount)
end

# returns a new array with the last amount elements.
def last_n(amount)
self.skip(self.size - amount)
end

# same as last, only first (equal to take)
def first_n(amount)
self.take(amount)
self - self.first(amount)
end

def random
Expand Down

0 comments on commit 5d8347a

Please sign in to comment.