diff --git a/mrbgems/mruby-range-ext/mrblib/range.rb b/mrbgems/mruby-range-ext/mrblib/range.rb
index 7fc05c190..10c0cde62 100644
--- a/mrbgems/mruby-range-ext/mrblib/range.rb
+++ b/mrbgems/mruby-range-ext/mrblib/range.rb
@@ -53,6 +53,19 @@ class Range
return self.to_a.last(nv)
end
+ ##
+ # call-seq:
+ # rng.max -> obj
+ # rng.max {|a,b| block } -> obj
+ #
+ # Returns 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.
+ #
+ # (10..20).max #=> 20
+ # (10...20).max #=> 19
+ # ('a'..'z').max #=> "z"
+ #
def max(&block)
val = self.begin
last = self.end
@@ -75,6 +88,17 @@ class Range
super()
end
+ ##
+ # call-seq:
+ # rng.min -> obj
+ # rng.min {|a,b| block } -> obj
+ #
+ # Returns the minimum value in the range. For non-numeric ranges or when
+ # a block is given, it delegates to Enumerable#min.
+ #
+ # (10..20).min #=> 10
+ # ('a'..'z').min #=> "a"
+ #
def min(&block)
val = self.begin
last = self.end
@@ -97,9 +121,16 @@ class Range
super()
end
- # Compare two ranges and see if they overlap each other
- # (1..5).overlap?(4..6) # => true
- # (1..5).overlap?(7..9) # => false
+ ##
+ # call-seq:
+ # rng.overlap?(other_range) -> true or false
+ #
+ # Returns true if self and other_range have at least one element in common,
+ # false otherwise.
+ #
+ # (1..5).overlap?(4..6) #=> true
+ # (1..5).overlap?(7..9) #=> false
+ #
def overlap?(other)
raise TypeError, "argument must be a range" unless other.kind_of?(Range)
diff --git a/mrbgems/mruby-range-ext/src/range.c b/mrbgems/mruby-range-ext/src/range.c
index 8b293a4de..4eb12cd4b 100644
--- a/mrbgems/mruby-range-ext/src/range.c
+++ b/mrbgems/mruby-range-ext/src/range.c
@@ -19,14 +19,14 @@ r_less(mrb_state *mrb, mrb_value a, mrb_value b, mrb_bool excl)
/*
* call-seq:
- * rng.cover?(obj) -> true or false
+ * rng.cover?(obj) -> true or false
* rng.cover?(range) -> true or false
*
- * Returns +true+ if the given argument is within +self+, +false+ otherwise.
+ * Returns true if the given argument is within self, false otherwise.
*
- * With non-range argument +object+, evaluates with <= and <.
+ * With non-range argument object, evaluates with <= and <.
*
- * For range +self+ with included end value (#exclude_end? == false),
+ * For range self with included end value (exclude_end? == false),
* evaluates thus:
*
* self.begin <= object <= self.end
@@ -193,6 +193,13 @@ range_size(mrb_state *mrb, mrb_value range)
}
#endif /* MRB_NO_FLOAT */
+/*
+ * Internal helper method to check if a range would be empty given
+ * the specified begin, end, and exclude_end parameters.
+ * Returns true if the range would be empty, false otherwise.
+ * Used internally by overlap? and other range methods.
+ */
+
static mrb_value
range_empty_p(mrb_state *mrb, mrb_value range)
{