Class: Array
- Defined in:
- lib/plist4r/mixin/ruby_stdlib.rb
Instance Methods
Instance Method Details
- (true, false) multidim?
And array is considered multi-dimensional if all of the first-order elements are also arrays.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 36 def multidim? case self.size when 0 false else each do |e| return false unless e.class == Array end true end end |
- (Object) to_ranges
Converts an array of values (which must respond to #succ) to an array of ranges. For example,
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 51 def to_ranges array = self.compact.uniq.sort ranges = [] if !array.empty? # Initialize the left and right endpoints of the range left, right = array.first, nil array.each do |obj| # If the right endpoint is set and obj is not equal to right's successor # then we need to create a range. if right && obj != right.succ ranges << Range.new(left,right) left = obj end right = obj end ranges << Range.new(left,right) end ranges end |