Sha256: fda085d1d661d0173b24f5f85f063adc205e26eec6edcdb81ae9e018903e6eb7
Contents?: true
Size: 698 Bytes
Versions: 3
Compression:
Stored size: 698 Bytes
Contents
require 'protocol/core' class Person def initialize(name, size) @name, @size = name, size end attr_reader :name, :size def <=>(other) size <=> other.size end conform_to Comparing end goliath = Person.new 'Goliath', 2_60 david = Person.new 'David', 1_40 symbol = Person.new 'The artist formerly known as Prince', 1_40 david < goliath # => true david >= goliath # => false david == symbol # => true begin class NoPerson def initialize(name, size) @name, @size = name, size end attr_reader :name, :size conform_to Comparing end rescue Protocol::CheckFailed => e e.to_s # => "Comparing#<=>(1): method '<=>' not implemented in NoPerson" end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
protocol-0.8.2 | examples/comparing.rb |
protocol-0.8.0 | examples/comparing.rb |
protocol-0.8.1 | examples/comparing.rb |