Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/core_extension/array.rb
Overview
Extention of ruby’s standard array.
Class Method Summary collapse
-
.wrap(object) ⇒ Object
This wrap method is taken from ActiveSupport and simply wraps an object into an array.
Instance Method Summary collapse
Class Method Details
.wrap(object) ⇒ Object
This wrap method is taken from ActiveSupport and simply wraps an object into an array.
20 21 22 23 24 25 26 27 28 |
# File 'lib/core_extension/array.rb', line 20 def self.wrap(object) if object.nil? [ ] elsif object.respond_to?(:to_ary) object.to_ary else [ object ] end end |
Instance Method Details
#resize(length, element = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/core_extension/array.rb', line 5 def resize(length, element = nil) case size <=> length when 1 slice 0, length when -1 result = self.dup result << element while result.size < length result when 0 self end end |