Class: Civil::Array
- Inherits:
-
Array
- Object
- Array
- Civil::Array
- Defined in:
- lib/civil/array.rb
Instance Method Summary collapse
- #<<(o) ⇒ Object
-
#initialize(*args, &block) ⇒ Array
constructor
A new instance of Array.
- #pluck(key) ⇒ Object
- #where(attrs) ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ Array
Returns a new instance of Array.
3 4 5 6 7 8 9 |
# File 'lib/civil/array.rb', line 3 def initialize(*args, &block) if args[0].is_a? ::Array args[0] = args[0].map { |e| e.is_a?(::Hash) ? Civil::Hash.new.merge(e) : e } end super end |
Instance Method Details
#<<(o) ⇒ Object
11 12 13 14 15 |
# File 'lib/civil/array.rb', line 11 def <<(o) o and o.is_a?(::Hash) and o = Civil::Hash.new.merge(o) super end |
#pluck(key) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/civil/array.rb', line 25 def pluck(key) raise ArgumentError, "key must be a symbol" unless key.is_a? Symbol self.inject(Civil::Array.new) { |arr, item| item.is_a?(Civil::Hash) and arr << item[key] arr } end |
#where(attrs) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/civil/array.rb', line 17 def where(attrs) self.inject(Civil::Array.new) { |arr, item| item.is_a?(Civil::Hash) and item =~ attrs and arr << item arr } end |