File: sample.rb

package info (click to toggle)
ruby-mtrc 0.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: ruby: 104; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Mtrc::Sample
  # A simple key/value pair, where the keys are comparable.
  # Useful for storing associated information in a set of samples; for example,
  #
  # s = SortedSamples.new
  # s << Sample.new(1, "The first request")
  # s << Sample.new(2, "The second request")
  #
  # Which request cost the most?
  # (s % 100).value # => "The second request"

  include Comparable

  attr_accessor :key
  attr_accessor :value
  def initialize(key, value)
    @key = key
    @value = value
  end

  def <=>(o)
    self.key <=> o.key
  end
end