lib/core/facets/comparable/cmp.rb in facets-2.4.5 vs lib/core/facets/comparable/cmp.rb in facets-2.5.0

- old
+ new

@@ -7,27 +7,27 @@ # 3.cmp(10) #=> -1 # # This fundamental compare method is used to keep # comparison compatible with <tt>#succ</tt>. # - # CREDIT Peter Vanbroekhoven + # CREDIT: Peter Vanbroekhoven def cmp(o) self<=>o end end -class String +class String # Compare method that takes length into account. # Unlike #<=>, this is compatible with #succ. # # "abc".cmp("abc") #=> 0 # "abcd".cmp("abc") #=> 1 # "abc".cmp("abcd") #=> -1 # "xyz".cmp("abc") #=> 1 # - # CREDIT Peter Vanbroekhoven + # CREDIT: Peter Vanbroekhoven def cmp(other) return -1 if length < other.length return 1 if length > other.length self <=> other # alphabetic compare