#-- # 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