Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LogEntry
- end
- EntryType = { :error => 0, :warning => 1, :info => 2 }
- LogEntry.EntryType[:error]
- class LogEntry
- EntryType = { :error => 0, :warning => 1, :info => 2 }
- end
- LogEntry::EntryType[:error]
- class LogEntry
- def self.types
- { :error => 0, :warning => 1, :info => 2 }
- end
- end
- # And a simple test
- LogEntry.types[:error].should be_an_instance_of(Hash)
- class LogEntry
- @@ErrorType = 0
- End
- LogEntry.ErrorType
- class LogEntry
- attr_reader :type
- ERROR_RANKING = [ :error, :warning, :info, ]
- include Comparable
- def initialize( type )
- @type = type
- end
- def <=>( other )
- ERROR_RANKING.index( @type ) <=> ERROR_RANKING.index( other.type )
- end
- end
- entry1 = LogEntry.new( :error )
- entry2 = LogEntry.new( :warning )
- puts entry1.type.inspect
- #=> :error
- puts entry2.type.inspect
- #=> :warning
- puts( ( entry1 > entry2 ).inspect )
- #=> false
- puts( ( entry1 < entry2 ).inspect )
- #=> true
Add Comment
Please, Sign In to add comment