Sha256: a0c4043b8ea985309c01113f0be0b2b0768830ce690f3f24b63a75e6eaf95429

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 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 library is free software; you can redistribute it and/or
#     modify it under the terms of the GNU Lesser General Public
#     License as published by the Free Software Foundation; either
#     version 2.1 of the License, or (at your option) any later version.
#
#     This library 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
#     Lesser General Public License for more details.
#
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#++

module Prelude

  # $Id: tuple.rb 7 2006-09-06 17:03:26Z prelude $
  # 
  # The Tuple's being an Array should be considered an implementation inheritance.
  class Tuple < Array

    def initialize(*args)
      case
      when args.nil? || args.empty? :
          self[0] = self[1] = nil
      when args.length == 1 && args[0].kind_of?(Array) :
          self[0] = args[0][0]
          self[1] = args[0][1..-1]
      when args.length == 1         :
          self[0] = args[0]
          self[1] = nil
      when args.length == 2         :
          self[0] = args[0]
          self[1] = args[1]
      when args.length  > 2         :
          self[0] = args[0]
          self[1] = args[1..-1]
      end # case
    end

    def fst
      self[0]
    end

    def snd
      self[1]
    end

  end # Tuple

end # Prelude

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prelude-0.0.3 lib/prelude/tuple.rb
prelude-0.0.2 lib/prelude/tuple.rb