Created
July 28, 2011 17:04
-
-
Save cwgem/1111961 to your computer and use it in GitHub Desktop.
Comparableの使用例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Employee | |
| attr_accessor :first_name | |
| attr_accessor :last_name | |
| attr_accessor :monthly_sales | |
| include Comparable | |
| # 月間売上高で社員をソート | |
| def <=>(other_employee) | |
| other_employee.monthly_sales <=> @monthly_sales | |
| end | |
| def to_s | |
| "#{@first_name} #{@last_name}: #{@monthly_sales}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment