Skip to content

Commit

Permalink
Add Native::Array#last
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Sep 18, 2013
1 parent 958bb3f commit d61b661
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions corelib/native.rb
Expand Up @@ -99,6 +99,22 @@ def []=(index, value)
end
end

def last(count = nil)
if count
index = last - 1
result = []

while index >= 0
result << self[index]
index -= 1
end

result
else
self[length - 1]
end
end

def length
`#@native[#@length]`
end
Expand Down

0 comments on commit d61b661

Please sign in to comment.