Sha256: 4e2cecb1bd9e7082cd17578e7f5bf3864c1602e06c7f87829f6eba7cf194c50b
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
#-- # Tuple # # Copyright (c) 2005 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or # redistribute this software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # ========================================================================== # Revision History: # ========================================================================== # 2005.04.24 trans # Adjusted to use Tuple::[] instead of ::new, which now takes a single # argument, either an Array or a String which it splits. # 2005.04.24 trans # Created. # ========================================================================== # # TODO: Not a true tuple? # This class probably needs some enhancements to be truly considered a # Tuple. For instance, should a Tuple by multiton? # #++ #:title: Tuple # # A Tuple is essentially an Array that is also Comaparable. # # == Usage # # t1 = Tuple[1,2,3] # t2 = Tuple[2,3,4] # # t1 < t2 #=> true # t1 > t2 #=> false # class Tuple < Array include Comparable def self.[](*args) new(args) end def initialize(arg) super() @divider = '.' case arg when String if md = /([-.,;:'\\\/])/.match(arg) @divider = md[1] end self.concat arg.split(/([-.,;:'\\\/])/) else self.concat arg end end def to_s join(@divider) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin testing require 'test/unit' class TC_Tuple < Test::Unit::TestCase def setup @t1 = Tuple[1,2,3] @t2 = Tuple[2,4,5] end def test_compare assert( @t1 < @t2 ) assert( @t2 > @t1 ) end end =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.9.0 | lib/mega/tuple.rb |