Created
October 9, 2017 02:30
-
-
Save hisanari/94e2d161af87fc608d5b20bb06ead628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyArray < Array | |
include Comparable | |
# 配列の最小値で比較できるようにオーバーライド | |
def <=> ( anotherArray ) | |
self.min <=> anotherArray.min | |
end | |
end | |
myarr1 = MyArray.new([0,1,2,3]) | |
myarr2 = MyArray.new([1,2,3,4]) | |
myarr2 = MyArray.new([1,2,3,4]) | |
myarr3 = MyArray.new([0,1,2,3,5]) | |
puts( "MyArray" ) | |
p( myarr1 < myarr2 ) | |
p( myarr1 > myarr2 ) | |
p( myarr1 == myarr2 ) | |
p( myarr3 > myarr1 ) | |
p( myarr3 <=> myarr1 ) | |
p( myarr1 <=> myarr2 ) | |
p( myarr2 == myarr2_2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment