Skip to content

Instantly share code, notes, and snippets.

@taq
Created April 18, 2013 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taq/5413857 to your computer and use it in GitHub Desktop.
Save taq/5413857 to your computer and use it in GitHub Desktop.
Using the "starship" operator
class Pessoa
include Comparable
attr_accessor :nome
def initialize(nome)
self.nome = nome
end
def <=>(outra)
return -1 if outra.size<self.nome.size
return 1 if outra.size>self.nome.size
return 0
end
end
p = Pessoa.new("vinicius")
puts p == "taq"
puts p == "vinicius"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment