# begin / end return nilp(..10).begin# => nilp(1..).end# => nil# But, first / last raise an exceptionp(..10).first# Error: in `first': cannot get the first element of beginless range (RangeError)p(1..).last# Error: in `last': cannot get the last element of endless range (RangeError)# Returns Infinity if it is a Numericp(1..10).size# => 10p(1..).size# => Infinityp(..1).size# => Infinity# Otherwise returns nilp("a".."z").size# => nilp("a"..).size# => nilp(.."z").size# => nil
(..10).begin return nil, but (..10).first raise an exception.
(1..).size return Infinity, but ("a"..).size return nil.
Behavior changes depending on the state of Range and the called method.
It is difficult to determine if it is an infinite range.
I think the proposal makes sense. The method names are a bit odd though.
I have no huge qualms with the inf* related methods, such as infinite? or
finite? although it reads a bit odd; but I think that .beginless? and
.endless? are very clumsy names.
Unfortunately I do not have better alternative suggestions either.
Perhaps it could suffice to only add e. g. ".infinite?" and we may not
even need ".finite?".
The use case on the other hand is clear to me, IMO, in particular
"(1..).size return Infinity, but ("a"..).size return nil." so it
would make sense to give ruby users the ability to check for
infinite in advance, rather than check for nil lateron.
I think that there is no relation between Float::INFINITY and infinite Range
I guess a/any concept of infinity should not necessarily be intrinsicalled
tied down to a particular constant (e. g. Float::INFINITY) per se; in the latter
case it would seem more like an implementation detail (to me), rather than a
more general concept for/of infinity.
I think infinite? is a different concept, which already exists as Numeric#infinite?, and should definitely handle the Float::INFINITY case if introduced.
I think infinite? is a different concept, which already exists as Numeric#infinite?, and should definitely handle the Float::INFINITY case if introduced
Do you mean that Range#infinite? is no longer needed if the behavior of ("a"..).size is changed? If not, I think it is a different topic from this ticket.
I am against having finite? or infinite? methods. I don't think there's use-case for those methods.
Meanwhile, I see the small possibility for the usage of beginless? and endless? methods. But I don't like the names.
Having negative meaning in the method name would make it complicated. Having begin? and end? instead of beginless? and endless? would be more natural, and easy to comprehend.
is not straightforward; it is twisted. The intent of the elsif range.beginless? condition is actually to check whether the end exists, not whether the beginning is absent. Using begin? and end?, a more straightforward code can be written as follows (I also believe your last condition is redundant, and there is no case that corresponds to your else case).
defsearch_in(range)query="/search"ifrange.finite?"#{query}?from=#{range.begin}&to=#{range.end}"elsifrange.end?"#{query}?to=#{range.end}"else# `range.begin?` is always `true`"#{query}?from=#{range.begin}"endend