mrbgems/mruby-range-ext/README.md
This gem extends the functionality of Ruby's Range class in mruby. It provides several new methods to make working with ranges more convenient and powerful.
first / first(n)Returns the first object in the range, or an array of the first n elements.
Example:
(10..20).first #=> 10
(10..20).first(3) #=> [10, 11, 12]
last / last(n)Returns the last object in the range, or an array of the last n elements. Note that with no arguments last will return the object that defines the end of the range even if exclude_end? is true.
Example:
(10..20).last #=> 20
(10...20).last #=> 20
(10..20).last(3) #=> [18, 19, 20]
(10...20).last(3) #=> [17, 18, 19]
maxReturns the maximum value in the range. Returns nil if the range is empty or excludes its end and the end is not an Integer. For non-numeric ranges or when a block is given, it delegates to Enumerable#max.
Example:
(10..20).max #=> 20
(10...20).max #=> 19
('a'..'z').max #=> "z"
minReturns the minimum value in the range. For non-numeric ranges or when a block is given, it delegates to Enumerable#min.
Example:
(10..20).min #=> 10
('a'..'z').min #=> "a"
overlap?(other_range)Returns true if self and other_range have at least one element in common.
Example:
(1..5).overlap?(4..6) #=> true
(1..5).overlap?(7..9) #=> false
cover?(obj_or_range)Returns true if the given object or all elements of the given range are within self.
Example:
("a".."z").cover?("c") #=> true
("a".."z").cover?("5") #=> false
("a".."z").cover?("cc") #=> true # Note: This behavior might be surprising for strings.
(1..5).cover?(2..4) #=> true
(1..5).cover?(2..7) #=> false
sizeReturns the number of elements in the range. Both the begin and the end of the Range must be Numeric, otherwise nil is returned. For endless ranges with an Integer beginning, it returns Infinity.
Example:
(10..20).size #=> 11
('a'..'z').size #=> nil
(1..).size #=> Infinity
This gem is released under the MIT License.