class Magick::Image::View::Rows

def cols(*args)

def cols(*args)
  @cols = args[0] # remove the outermost array
  @unique = false
  # Convert @rows to an Enumerable object
  case @rows.length
  when 0                      # Create a Range for all the rows
    @rows = Range.new(0, @height, true)
  when 1                      # Range, Array, or a single integer
    # if the single element is already an Enumerable
    # object, get it.
    if @rows.first.respond_to? :each
      @rows = @rows.first
    else
      @rows = Integer(@rows.first)
      @rows += @height if @rows < 0
      Kernel.raise IndexError, "index [#{@rows}] out of range" if @rows < 0 || @rows > @height - 1
      # Convert back to an array
      @rows = Array.new(1, @rows)
      @unique = true
    end
  when 2
    # A pair of integers representing the starting column and the number of columns
    start = Integer(@rows[0])
    length = Integer(@rows[1])
    # Negative start -> start from last row
    start += @height if start < 0
    if start > @height || start < 0 || length < 0
      Kernel.raise IndexError, "index [#{@rows.first}] out of range"
    elsif start + length > @height
      length = @height - length
      length = [length, 0].max
    end
    # Create a Range for the specified set of rows
    @rows = Range.new(start, start + length, true)
  end
  case @cols.length
  when 0 # all rows
    @cols = Range.new(0, @width, true) # convert to range
    @unique = false
  when 1 # Range, Array, or a single integer
    # if the single element is already an Enumerable
    # object, get it.
    if @cols.first.respond_to? :each
      @cols = @cols.first
      @unique = false
    else
      @cols = Integer(@cols.first)
      @cols += @width if @cols < 0
      Kernel.raise IndexError, "index [#{@cols}] out of range" if @cols < 0 || @cols > @width - 1
      # Convert back to array
      @cols = Array.new(1, @cols)
      @unique &&= true
    end
  when 2
    # A pair of integers representing the starting column and the number of columns
    start = Integer(@cols[0])
    length = Integer(@cols[1])
    # Negative start -> start from last row
    start += @width if start < 0
    if start > @width || start < 0 || length < 0
    # nop
    elsif start + length > @width
      length = @width - length
      length = [length, 0].max
    end
    # Create a Range for the specified set of columns
    @cols = Range.new(start, start + length, true)
    @unique = false
  end
end