Class: Range
Overview
HotCocoa extensions to the Range class
Instance Method Summary collapse
-
#to_NSRange(length = nil) ⇒ Object
deprecated
Deprecated.
MacRuby 0.11+ includes
Range#relative_to
. This API will be dropped in HotCocoa 0.8.
Instance Method Details
#to_NSRange(length = nil) ⇒ Object
Deprecated.
MacRuby 0.11+ includes Range#relative_to
.
This API will be dropped in HotCocoa 0.8.
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.
27 28 29 30 31 32 33 34 |
# File 'lib/hotcocoa/core_extensions/range.rb', line 27 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 |