Class: Range
Overview
HotCocoa extensions to the Range class
Instance Method Summary collapse
-
#to_NSRange(length = nil) ⇒ Object
Create a Cocoa NSRange from a Ruby Range.
Instance Method Details
#to_NSRange(length = nil) ⇒ Object
Create a Cocoa NSRange from a Ruby Range.
Since NSRange does not support negative indexing, you MUST include an argument to this method to indicate the length of the object which the range refers to.
22 23 24 25 26 27 28 29 |
# File 'lib/hotcocoa/core_extensions/range.rb', line 22 def to_NSRange length = nil if (first.negative? or last.negative?) and !length raise ArgumentError, 'arg required if range has negative indicies' end start = (first.negative? ? length + first : first) run = (last.negative? ? length + last : last ) - start + (exclude_end? ? 0 : 1) NSRange.new start, run end |