Module: Array::ArrayExtensions

Included in:
Array
Defined in:
lib/libmatty/array.rb

Instance Method Summary collapse

Instance Method Details

#extract_options!Object



26
27
28
# File 'lib/libmatty/array.rb', line 26

def extract_options!
    last.is_a?(::Hash) ? pop : {}
end

#kassoc(k) ⇒ Object

return first hash-like element with key k



15
16
17
18
# File 'lib/libmatty/array.rb', line 15

def kassoc(k)
    each { |h| return h if h.try(:has_key?, k) }
    return nil
end

#kind_of_these?(y) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/libmatty/array.rb', line 10

def kind_of_these? y
    inject(false) {|acc, klass| acc || y.kind_of?(klass)}
end

#strip(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/libmatty/array.rb', line 30

def strip(*args)
    list=[]

    self.each_with_index do | e, i |
        if(not args.member?(i))
            list << e
        end
    end
    return list
end

#to_hashObject

Assume an array of key, value tuples, and convert to Hash



4
5
6
7
8
# File 'lib/libmatty/array.rb', line 4

def to_hash
    r = {}
    each {|it| r[it[0]] = it[1]}
    return r
end

#vassoc(v) ⇒ Object

return first hash-like element with value v



21
22
23
24
# File 'lib/libmatty/array.rb', line 21

def vassoc(v)
    each { |h| return h if h.try(:has_value?, v) }
    return nil
end