ruby: add vector.first/last

develop
jj 2012-07-06 13:25:47 +02:00
parent 1c5b5b956f
commit bef5079d43
1 changed files with 3 additions and 1 deletions

@ -354,7 +354,9 @@ module DFHack
end end
def empty? ; length == 0 ; end def empty? ; length == 0 ; end
def flatten ; map { |e| e.respond_to?(:flatten) ? e.flatten : e }.flatten ; end def flatten ; map { |e| e.respond_to?(:flatten) ? e.flatten : e }.flatten ; end
def index(elem=nil, &b) ; (0...length).find { |i| b ? b[self[i]] : self[i] == elem } ; end def index(e=nil, &b) ; (0...length).find { |i| b ? b[self[i]] : self[i] == e } ; end
def first ; self[0] ; end
def last ; self[length-1] ; end
end end
class StaticArray < MemStruct class StaticArray < MemStruct
attr_accessor :_tglen, :_length, :_indexenum, :_tg attr_accessor :_tglen, :_length, :_indexenum, :_tg