Sha256: 0efb410cd1a7138c0a8a682c88a20e977edfc8b016d31997536b83a34d549c1c

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

#-- 
#     This file is part of the Prelude library that provides tools to
#     enable Haskell style functional programming in Ruby.
#
#     http://prelude.rubyforge.org 
#     
#     Copyright (C) 2006 APP Design, Inc.
#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#
#     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.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License along
#     with this program; if not, write to the Free Software Foundation, Inc.,
#     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#++

module Prelude

  # $Id: tuple.rb 2 2006-08-25 00:11:17Z prelude $
  #
  class Tuple < Array

    def new(*args)
      case
      when args.nil? || args.empty? :
          super.new([nil, nil])
      when args.lengh == 1 && args[0].kind_of(Array) :
          super.new(args[0][0])
          self << super.new([args[0][1..-1]])
      when args.lengh == 1 :
          super.new([args[0], nil])
      when args.lengh == 2          :
          super.new(args)
      when args.lengh  > 2          :
          super.new([args[0], args[1..-1]])
      end # case
    end

    def fst
      self[0]
    end

    def snd
      self[1]
    end

    def fst=(o)
      self[0] = o
    end

    def snd=(o)
      self[1] = o
    end

  end # Tuple

end # Prelude

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prelude-0.0.1 lib/prelude/tuple.rb