end include Comparable def <=> other self.name <=> other.name end end users = %w{Bob Carol Eve Mallory Alice Dave}.map {|n| User.new(n)} users.sort.map {|u| u.name} # => ["Alice", "Bob", "Carol", "Dave", "Eve", "Mallory"] alice = User.new("Alice") bob = User.new("Bob") bob > alice # => true Mix-inek
Hunter def hap_hap puts "haphap" end end duck = Duck.new; hunter = Hunter.new duck.respond_to?(:hap_hap) # => true hunter.respond_to?(:hap_hap) # => true gun.shoot(hunter) Duck typing “If it walks like a duck and quacks like a duck, I would call it a duck.“