Sha256: 7f7b9c1f635fedda42f506b5ae159aad9571fee0dc11c4e58a3595b7945749d3

Contents?: true

Size: 966 Bytes

Versions: 17

Compression:

Stored size: 966 Bytes

Contents

class NSIndexPath

  def to_a
    indexes_ptr = Pointer.new(:uint, self.length)
    self.getIndexes indexes_ptr
    a = []
    self.length.times do |i|
      a << indexes_ptr[i]
    end
    a
  end

  def to_s
    "<NSIndexPath #{to_a.to_s}>"
  end

end


# This class is used in `switch` statements.  Easy pattern matching, so instead
# of `if index_path.row...index_path.section`, you can use
# `when IndexPath[row, section]`
class IndexPath

  def self.[] *values
    IndexPath.new values
  end

  def initialize values
    @values = values
  end

  def === other
    return true if super

    if other.is_a? NSIndexPath
      other = other.to_a
    end

    if other.is_a? Enumerable
      ret = true
      other_i = 0
      @values.each do |val|
        next_val = other[other_i]
        other_i += 1
        unless val == true || val === next_val
          ret = false
          break
        end
      end

      return ret
    end
    return false
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sugarcube-0.20.25 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.24 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.23 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.22 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.21 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.20 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.19 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.18 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.17 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.16 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.15 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.13 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.12 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.11 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.10 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.9 lib/sugarcube/nsindexpath.rb
sugarcube-0.20.8 lib/sugarcube/nsindexpath.rb