|
File test.rb, 273 bytes
(added by macruby@…, 2 years ago)
|
|
source code
|
| Line | |
|---|
| 1 | class Test |
|---|
| 2 | attr :min |
|---|
| 3 | def initialize(min) |
|---|
| 4 | @min = min |
|---|
| 5 | end |
|---|
| 6 | def <=>(other) |
|---|
| 7 | min <=> other.min |
|---|
| 8 | end |
|---|
| 9 | end |
|---|
| 10 | |
|---|
| 11 | class PQ < Array |
|---|
| 12 | def <<(other) |
|---|
| 13 | super other |
|---|
| 14 | sort! |
|---|
| 15 | end |
|---|
| 16 | end |
|---|
| 17 | |
|---|
| 18 | a = Test.new(10.0) |
|---|
| 19 | b = Test.new(10.1) |
|---|
| 20 | d = Test.new(9.1) |
|---|
| 21 | c = PQ.new |
|---|
| 22 | c << a |
|---|
| 23 | c << b |
|---|
| 24 | c << d |
|---|
Download in other formats: