Module: Array::ArrayExtensions
- Included in:
- Array
- Defined in:
- lib/ruckus/extensions/array.rb
Instance Method Summary collapse
- #extract_options! ⇒ Object
-
#kassoc(k) ⇒ Object
return first hash-like element with key k.
- #kind_of_these?(y) ⇒ Boolean
-
#to_hash ⇒ Object
Assume an array of key, value tuples, and convert to Hash.
-
#vassoc(v) ⇒ Object
return first hash-like element with value v.
Instance Method Details
#extract_options! ⇒ Object
28 29 30 |
# File 'lib/ruckus/extensions/array.rb', line 28 def last.is_a?(::Hash) ? pop : {} end |
#kassoc(k) ⇒ Object
return first hash-like element with key k
15 16 17 18 19 |
# File 'lib/ruckus/extensions/array.rb', line 15 def kassoc(k) # XXX not used each { |h| return h if h.try(:has_key?, k) } return nil end |
#kind_of_these?(y) ⇒ Boolean
10 11 12 |
# File 'lib/ruckus/extensions/array.rb', line 10 def kind_of_these? y inject(false) {|acc, klass| acc || y.kind_of?(klass)} end |
#to_hash ⇒ Object
Assume an array of key, value tuples, and convert to Hash
4 5 6 7 8 |
# File 'lib/ruckus/extensions/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
22 23 24 25 26 |
# File 'lib/ruckus/extensions/array.rb', line 22 def vassoc(v) # XXX not used each { |h| return h if h.try(:has_value?, v) } return nil end |