<=>
operator that is not in lexicographical order.
If you sort normally in 2., it will not be in lexicographic order, of course. (Because it is judged that the longer the character string is, the larger it is)[Note] What is Kinx? First motive ⇒ Please see here Repository ⇒ Please see here
Let's try " b "<=>" aa "
with irb,
irb(main):001:0> "b" <=> "aa"
=> 1
irb(main):002:0>
** What? !! ** **
So what about Range? When I try to display " a ".." c "
.
irb(main):002:0> a = "a".."c"
=> "a".."c"
irb(main):003:0> a.each {|e| p e }
"a"
"b"
"c"
=> "a".."c"
It will be listed properly. So what about the alleged " b ".." aa "
?
irb(main):004:0> a = "b".."aa"
=> "b".."aa"
irb(main):005:0> a.each {|e| p e }
=> "b".."aa"
Why can't I use " b ".." aa "
...
After all, " b ".." aa "
also ** wants you to move **, isn't it? After " b "
is"c"
, I wanted you to continue to"z"
and then end with"aa"
, but what about other people?
So, in Latest repository (not included in 0.8.1), I modified it as follows.
<=>
operator of the string is returned in lexicographic order.<=>
part of class Range
is treated specially only for character strings so that"b" .. "aa"
can also be used." b "," c "," d ", ...," z "," aa "
.So, here (= Specification of Range for characters) is different from Ruby. Please let us know if you have any problems.
Well, I don't use it much under such special conditions, so no one seems to be in trouble. So if you say which one is fine, it may be either one. It was a detailed story.
How about Ruby? Is it within expectations or unexpected? Is it intentional or not? Well, the definition is clear and the operation follows the definition, so it seems calm with this kind of thing = specification.
See you next time.
Recommended Posts