ludy 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,4 +1,15 @@
1
1
 
2
+ ==============================
3
+ ludy 0.0.7
4
+
5
+ 1. ludy_ext:
6
+ added:
7
+ 1. Array#untranspose
8
+ 2. Array#unzip
9
+ 3. Array#combine!
10
+ 4. Object#m
11
+ 5. Kernel#id
12
+
2
13
  ==============================
3
14
  ludy 0.0.6, 2007.09.15
4
15
 
@@ -17,6 +17,7 @@
17
17
  # require 'singleton'
18
18
 
19
19
  class Object
20
+ alias_method :m, :method
20
21
  def tap
21
22
  yield self
22
23
  self
@@ -75,6 +76,16 @@ class Array
75
76
  init
76
77
  end
77
78
  def combine *target; self.zip(*target).map &:'inject &:+'.to_msg; end
79
+ def combine! *target; replace combine(*target); end
80
+ def untranspose
81
+ result = ([nil]*self.first.size).map{[]}
82
+ self.each{ |zipped|
83
+ zipped = zipped.clone
84
+ result.each{ |r| r << zipped.shift }
85
+ }
86
+ result
87
+ end
88
+ def unzip; self.untranspose.first; end
78
89
  end
79
90
 
80
91
  class Proc
@@ -100,6 +111,7 @@ class Proc
100
111
  end
101
112
 
102
113
  module Kernel
114
+ def id a = nil; a.nil? ? self : a; end
103
115
  def curry
104
116
  class << self
105
117
  alias_method :orig_call, :call
@@ -18,7 +18,7 @@ require 'rubygems'
18
18
 
19
19
  spec = Gem::Specification.new{|s|
20
20
  s.name = 'ludy'
21
- s.version = '0.0.6'
21
+ s.version = '0.0.7'
22
22
  s.author = 'Lin Jen-Shin(a.k.a. godfat)'
23
23
  s.email = 'strip number: 135godfat7911@246godfat.890org'
24
24
  s.homepage = 'http://ludy.rubyforge.org/'
@@ -120,5 +120,29 @@ class TestLudyExt < Test::Unit::TestCase
120
120
  a = [[1,2],[3,4],[5,6]]
121
121
  assert_equal [9, 12], a.inject(&:combine)
122
122
  assert_equal [9, 12], a.shift.combine(*a)
123
+
124
+ a = [18,29]
125
+ a.combine! [12, 1]
126
+ assert_equal [30, 30], a
127
+ end
128
+
129
+ def test_unzip_and_untranspose
130
+ a = [1,2,3]
131
+ b = %w{a b c}
132
+ assert_equal [a, b], a.zip(b).untranspose
133
+ assert_equal [a, b], [a, b].transpose.untranspose
134
+ assert_equal a, a.zip(b).unzip
135
+
136
+ c = [nil, false, true]
137
+ assert_equal [a, b, c], a.zip(b, c).untranspose
138
+ assert_equal [a, b, c], [a, b, c].transpose.untranspose
139
+ assert_equal a, a.zip(b, c).unzip
140
+ end
141
+
142
+ def test_id_and_m
143
+ assert_equal 'XD', id('XD')
144
+ assert_equal 'Orz', 'Orz'.id
145
+ assert_equal [1,3], [1,3].map(&m(:id))
146
+ assert_equal [2,4], [2,4].map(&:id)
123
147
  end
124
148
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ludy
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.6
7
- date: 2007-09-15 00:00:00 +08:00
6
+ version: 0.0.7
7
+ date: 2007-10-08 00:00:00 +08:00
8
8
  summary: Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library.
9
9
  require_paths:
10
10
  - lib