Sha256: 2535854c1dbee129d85b32894ef9f758b11f19788cc2523b217b2cd5c8f87b61

Contents?: true

Size: 996 Bytes

Versions: 97

Compression:

Stored size: 996 Bytes

Contents

# This class is used in `switch` statements.  Easy pattern matching, so instead
# of `if index_path.section == N && index_path.row = X`, you can use
# `when IndexPath[section, row]`.
#
# Example:
#
#     case index_path
#     when IndexPath[0, 0]  # first section, first row
#     when IndexPath[1]     # second section, any row
#     when IndexPath[2, 0..N]  # third section, 0..Nth rows
#     when IndexPath[2]     # all other in third section
#     end
#
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

97 entries across 97 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.5.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.4.2 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.4.1 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.4.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.7 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.6 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.5 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.4 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.3 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.2 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.1 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.3.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.2.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.1.1 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.1.0 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.0.8 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.0.7 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.0.6 lib/cocoa/sugarcube-indexpath/indexpath.rb
sugarcube-3.0.5 lib/cocoa/sugarcube-indexpath/indexpath.rb