lib/prelude/tuple.rb in prelude-0.0.1 vs lib/prelude/tuple.rb in prelude-0.0.2
- old
+ new
@@ -4,60 +4,56 @@
#
# 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 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 program is distributed in the hope that it will be useful,
+# 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 General Public License for more details.
+# 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 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.
+# 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 2 2006-08-25 00:11:17Z 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 new(*args)
+ def initialize(*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]])
+ 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
-
- def fst=(o)
- self[0] = o
- end
-
- def snd=(o)
- self[1] = o
end
end # Tuple
end # Prelude