fork download
  1. class Osoba
  2. attr_accessor :ime, :prezime
  3.  
  4. def initialize ime, prezime
  5. self.ime = ime
  6. self.prezime = prezime
  7. end
  8.  
  9. def <=> other
  10. rez = self.prezime <=> other.prezime
  11. return self.ime <=> other.ime if rez == 0
  12. return rez
  13. end
  14.  
  15. def to_s
  16. "#{ime} #{prezime}"
  17. end
  18. end
  19.  
  20. nesortiran_niz_osoba = [
  21. Osoba.new('Pera', 'Peric'),
  22. Osoba.new('Bora', 'Peric'),
  23. Osoba.new('Bora', 'Boric'),
  24. ]
  25.  
  26. nesortiran_niz_osoba.sort.each do |osoba|
  27. puts osoba
  28. end
  29.  
Success #stdin #stdout 0.01s 7464KB
stdin
Standard input is empty
stdout
Bora Boric
Bora Peric
Pera Peric