ludy 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +11 -0
- data/lib/ludy/ludy_ext.rb +12 -0
- data/ludy.gemspec +1 -1
- data/test/tc_ludy_ext.rb +24 -0
- metadata +2 -2
data/CHANGES
CHANGED
data/lib/ludy/ludy_ext.rb
CHANGED
@@ -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
|
data/ludy.gemspec
CHANGED
@@ -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.
|
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/'
|
data/test/tc_ludy_ext.rb
CHANGED
@@ -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.
|
7
|
-
date: 2007-
|
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
|