ludy 0.0.4 → 0.0.5

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 CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ==============================
3
+ ludy 0.0.5, 2007.09.15
4
+
5
+ i forgot what i'd done... (days ago)
6
+ but sure there's Symbol#to_proc and Symbol#to_msg,
7
+ also, please read unit test.
8
+
2
9
  ==============================
3
10
  ludy 0.0.4, 2007.08.12
4
11
 
data/lib/ludy.rb CHANGED
@@ -21,11 +21,3 @@ def require_ludy target = nil
21
21
  require_all_in_dir __FILE__, 'ludy'
22
22
  end
23
23
  end
24
-
25
- def require_all_in_dir target_file, *dirs
26
- dir = File.join(File.dirname(target_file), *dirs)
27
- Dir.foreach(dir){ |f|
28
- next unless f =~ /.rb$/
29
- require(File.join(dir, f))
30
- }
31
- end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Ludy
18
+
19
+
20
+ end
21
+
22
+ module Kernel
23
+ def cut target, &block
24
+ (class << target; self; end)
25
+ end
26
+ end
27
+
28
+ class Name
29
+ def name
30
+ 'name'
31
+ end
32
+ end
33
+
34
+ cut Name do
35
+ def name
36
+ "<#{super}>"
37
+ end
38
+ def g
39
+ '??'
40
+ end
41
+ end
data/lib/ludy/ludy_ext.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require 'singleton'
17
+ # require 'singleton'
18
18
 
19
19
  class Object
20
20
  def tap
@@ -63,7 +63,11 @@ end
63
63
  =end
64
64
 
65
65
  class Symbol
66
- def to_proc; lambda{|*args| args.shift.__send__ self, *args}; end
66
+ # def to_proc; lambda{|*args| args.shift.__send__ self, *args}; end
67
+ def to_proc
68
+ lambda{|*args| eval "args[0].#{self.to_s} #{args[1..-1].join ', '}" }
69
+ end
70
+ alias_method :to_msg, :to_proc
67
71
  end
68
72
 
69
73
  class Array
data/ludy.gemspec CHANGED
@@ -18,9 +18,9 @@ require 'rubygems'
18
18
 
19
19
  spec = Gem::Specification.new{|s|
20
20
  s.name = 'ludy'
21
- s.version = '0.0.4'
21
+ s.version = '0.0.5'
22
22
  s.author = 'Lin Jen-Shin(a.k.a. godfat)'
23
- s.email = 'strip number: 135godfat7911@246gmail.890com'
23
+ s.email = 'strip number: 135godfat7911@246godfat.890org'
24
24
  s.homepage = 'http://ludy.rubyforge.org/'
25
25
  s.platform = Gem::Platform::RUBY
26
26
  s.summary = 'Aims to extend Ruby standard library, providing some useful tools that\'s not existed in the standard library.'
data/test/tc_callstack.rb CHANGED
@@ -15,10 +15,11 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'test/unit'
18
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
19
19
  require_ludy 'callstack'
20
- include Ludy
20
+
21
21
  class TestCallstack < Test::Unit::TestCase
22
+ include Ludy
22
23
  def setup; @binding = 'XD' end
23
24
  def test_callstack
24
25
  called_line = __LINE__-1
data/test/tc_curry.rb CHANGED
@@ -15,17 +15,19 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'test/unit'
18
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
19
19
  require_ludy 'curry'
20
20
  require_ludy 'ludy_ext'
21
- include Ludy
21
+
22
22
  class Array
23
23
  def test_curry a, b, c, d, e
24
24
  [a, b, c, d, e]
25
25
  end
26
- include Curry
26
+ include Ludy::Curry
27
27
  end
28
+
28
29
  class TestCurry < Test::Unit::TestCase
30
+ include Ludy
29
31
  def test_curry
30
32
  func1 = [1,2,3].cfoldr[:-.to_proc]
31
33
  assert_equal 2, func1[0]
data/test/tc_dice.rb CHANGED
@@ -15,10 +15,11 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'test/unit'
18
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
19
19
  require_ludy 'dice'
20
- include Ludy
20
+
21
21
  class TestDice < Test::Unit::TestCase
22
+ include Ludy
22
23
  def test_dice
23
24
  50.times{ assert((1..20).include?(1.roll)) }
24
25
  50.times{ assert((2..40).include?(2.roll)) }
data/test/tc_lazy.rb CHANGED
@@ -15,10 +15,11 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'test/unit'
18
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
19
19
  require_ludy 'lazy'
20
- include Ludy
20
+
21
21
  class TestLazy < Test::Unit::TestCase
22
+ include Ludy
22
23
  def setup; @data = 0; end
23
24
  def get; @data += 1; end
24
25
  def test_lazy
data/test/tc_ludy_ext.rb CHANGED
@@ -15,8 +15,9 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'test/unit'
18
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
19
19
  require_ludy 'ludy_ext'
20
+
20
21
  class TestLudyExt < Test::Unit::TestCase
21
22
  def test_object_tap
22
23
  assert_equal '11', 10.tap{|i| assert_equal '10', i.to_s}.succ.to_s
@@ -106,4 +107,9 @@ class TestLudyExt < Test::Unit::TestCase
106
107
  f7 = lambda{|a| a*2}.compose f6.compose{|a,b| [b,a]}
107
108
  assert_equal 60, f7[3,5]
108
109
  end
110
+
111
+ def test_symbol_to_msg
112
+ assert_equal [3, 7], [[1,2],[3,4]].map(&:'inject(&:+)')
113
+ assert_equal 29, :'to_i*2+9'.to_msg['10']
114
+ end
109
115
  end
data/test/tc_rambda.rb CHANGED
@@ -17,14 +17,15 @@
17
17
  require 'test/unit'
18
18
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
19
19
  require_ludy 'rambda'
20
- include Ludy
20
+
21
21
  class TestRambda < Test::Unit::TestCase
22
+ include Ludy
22
23
  def test_rambda
23
24
  assert_equal(3628800, rambda{|n| n==1 ? 1 : n*this[n-1]}[10])
24
25
  assert_equal([1,1,2,3,5,8,13,21,34,55],
25
26
  (0...10).map(&rambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}))
26
27
 
27
28
  v = "can't refer v"
28
- assert_equal nil, rambda{v}.call
29
+ assert_raise(NameError){ rambda{v}.call }
29
30
  end
30
31
  end
data/test/tc_this.rb CHANGED
@@ -17,8 +17,9 @@
17
17
  require 'test/unit'
18
18
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
19
19
  require_ludy 'this'
20
- include Ludy
20
+
21
21
  class TestThis < Test::Unit::TestCase
22
+ include Ludy
22
23
  def test_fact
23
24
  assert_equal(120, fact(5))
24
25
  assert_equal(3628800, fact(10))
data/test/tc_variable.rb CHANGED
@@ -17,8 +17,9 @@
17
17
  require 'test/unit'
18
18
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
19
19
  require_ludy 'variable'
20
- include Ludy
20
+
21
21
  class TestVariable < Test::Unit::TestCase
22
+ include Ludy
22
23
  class Qoo
23
24
  def cool
24
25
  'cool ~~~~'
@@ -17,7 +17,9 @@
17
17
  require 'test/unit'
18
18
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
19
19
  require_ludy 'y_combinator'
20
- include Ludy
20
+
21
+ include Ludy # why should this be here?
22
+
21
23
  class TestYCombinator < Test::Unit::TestCase
22
24
  def test_y_combinator
23
25
  fact_ = lambda{|this|
@@ -17,8 +17,9 @@
17
17
  require 'test/unit'
18
18
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
19
19
  require_ludy 'z_combinator'
20
- include Ludy
20
+
21
21
  class TestZCombinator < Test::Unit::TestCase
22
+ include Ludy
22
23
  def test_z_combinator
23
24
  fact_ = lambda{|this|
24
25
  lambda{|n| n==1 ? 1 : n*this[n-1]}
data/test/ts_ludy.rb CHANGED
@@ -14,5 +14,27 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
18
- require_all_in_dir __FILE__
17
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
18
+ require_ludy 'ludy_ext'
19
+
20
+ dir = File.dirname __FILE__
21
+ lambda{ |log|
22
+ result = [0]*4
23
+ start = Time.new
24
+ log << "---- Start testing at #{start} ----\n"
25
+ Dir.foreach(dir){ |file|
26
+ next unless file =~ /^tc_/
27
+ test = File.join dir, file
28
+ # require test
29
+
30
+ # require is so slow...
31
+ # insted, we excute them separately
32
+ output = `#{test}`
33
+ log << output
34
+ match = output.match /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/
35
+ # result = result.zip(match[1..4].map(&:to_i)).map{|data| data.inject(&:+)}
36
+ result = result.zip(match[1..4].map(&:to_i)).map(&:'inject(&:+)')
37
+ }
38
+ log << "Total: #{result[0]} tests, #{result[1]} assertions, #{result[2]} failures, #{result[3]} errors\n\n"
39
+ log << "---- End testing in #{Time.new - start} seconds. ----\n\n\n\n\n"
40
+ }[STDOUT || $stdout]
metadata CHANGED
@@ -3,12 +3,12 @@ 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.4
7
- date: 2007-08-12 00:00:00 +08:00
6
+ version: 0.0.5
7
+ date: 2007-09-15 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
11
- email: "strip number: 135godfat7911@246gmail.890com"
11
+ email: "strip number: 135godfat7911@246godfat.890org"
12
12
  homepage: http://ludy.rubyforge.org/
13
13
  rubyforge_project:
14
14
  description:
@@ -34,6 +34,7 @@ files:
34
34
  - lib/lib/multi.rb
35
35
  - lib/lib/smulti.rb
36
36
  - lib/ludy
37
+ - lib/ludy/aspect.rb
37
38
  - lib/ludy/callstack.rb
38
39
  - lib/ludy/curry.rb
39
40
  - lib/ludy/dice.rb
@@ -62,7 +63,6 @@ files:
62
63
  - ludy.gemspec
63
64
  - NOTICE
64
65
  - README
65
- - svk-commit8wxPX.tmp
66
66
  - test
67
67
  test_files:
68
68
  - test/ts_ludy.rb
data/svk-commit8wxPX.tmp DELETED
@@ -1 +0,0 @@
1
- local ci?