Sha256: ba14315a86d76662b3e9d4559bda81954338b36665a843178c27b1a181590d64
Contents?: true
Size: 663 Bytes
Versions: 2
Compression:
Stored size: 663 Bytes
Contents
## Comparable.[] require 'facets/comparable/op_get' Allows `Comparable` to be included as a *parmetric mixin*. This makes it easy to define a class as comparable on a limited set of attributes. c = Class.new do include Comparable[:a,:b] attr_accessor :a, :b def initialize(a,b) @a=a; @b=b end end a = [c.new(10,20),c.new(10,30)] a.sort.assert == a a = [c.new(10,30),c.new(10,20)] a.sort.assert == a.reverse a = [c.new(10,10),c.new(20,10)] a.sort.assert == a a = [c.new(20,10),c.new(10,10)] a.sort.assert == a.reverse a = [c.new(10,30),c.new(20,10)] a.sort.assert == a
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
facets-glimmer-3.2.0 | demo/core/comparable/op_get.md |
facets-3.1.0 | demo/core/comparable/op_get.md |