ludy 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/CHANGES +88 -57
  2. data/Manifest.txt +96 -0
  3. data/NOTICE +10 -23
  4. data/README +173 -10
  5. data/Rakefile +33 -0
  6. data/TODO +5 -0
  7. data/bin/ludy +11 -0
  8. data/lib/ludy/all.rb +3 -0
  9. data/lib/ludy/array/body.rb +9 -0
  10. data/lib/ludy/array/combine.rb +16 -0
  11. data/lib/ludy/array/combos.rb +23 -0
  12. data/lib/ludy/array/filter.rb +4 -0
  13. data/lib/ludy/array/foldl.rb +5 -0
  14. data/lib/ludy/array/foldr.rb +8 -0
  15. data/lib/ludy/array/reverse_map.rb +7 -0
  16. data/lib/ludy/array/rotate.rb +22 -0
  17. data/lib/ludy/array.rb +3 -0
  18. data/lib/ludy/blackhole.rb +17 -0
  19. data/lib/ludy/class/undef_all_methods.rb +9 -0
  20. data/lib/ludy/class.rb +3 -0
  21. data/lib/ludy/deprecated/aspect.rb +26 -0
  22. data/lib/ludy/deprecated/callstack.rb +24 -0
  23. data/lib/ludy/deprecated/curry.rb +29 -0
  24. data/lib/ludy/deprecated/rambda.rb +23 -0
  25. data/lib/ludy/deprecated/this.rb +14 -0
  26. data/lib/ludy/deprecated/untranspose.rb +12 -0
  27. data/lib/ludy/deprecated/unzip.rb +7 -0
  28. data/lib/ludy/{dice.rb → dices.rb} +18 -22
  29. data/lib/ludy/kernel/defun.rb +10 -0
  30. data/lib/ludy/kernel/ergo.rb +16 -0
  31. data/lib/ludy/kernel/id.rb +6 -0
  32. data/lib/ludy/kernel/if_else.rb +14 -0
  33. data/lib/ludy/kernel/m.rb +5 -0
  34. data/lib/ludy/kernel/public_send.rb +13 -0
  35. data/lib/ludy/kernel/singleton_method.rb +13 -0
  36. data/lib/ludy/kernel/tap.rb +10 -0
  37. data/lib/ludy/kernel.rb +3 -0
  38. data/lib/ludy/lazy.rb +9 -16
  39. data/lib/ludy/message_dispatcher.rb +58 -0
  40. data/lib/ludy/pattern_matcher.rb +41 -0
  41. data/lib/ludy/proc/bind.rb +21 -0
  42. data/lib/ludy/proc/chain.rb +17 -0
  43. data/lib/ludy/proc/compose.rb +9 -0
  44. data/lib/ludy/proc/curry.rb +39 -0
  45. data/lib/ludy/proc.rb +3 -0
  46. data/lib/ludy/symbol/curry.rb +10 -0
  47. data/lib/ludy/symbol/to_msg.rb +10 -0
  48. data/lib/ludy/symbol/to_proc.rb +7 -0
  49. data/lib/ludy/symbol.rb +3 -0
  50. data/lib/ludy/tasks/erb_cpp/attr_builder.rb +49 -0
  51. data/lib/ludy/tasks/erb_cpp/header_guard.rb +12 -0
  52. data/lib/ludy/tasks/erb_cpp/template_forward_parameters.rb +43 -0
  53. data/lib/ludy/tasks/erb_cpp.rb +35 -0
  54. data/lib/ludy/tasks.rb +3 -0
  55. data/lib/ludy/test/helper.rb +3 -0
  56. data/lib/ludy/variable.rb +9 -17
  57. data/lib/ludy/y_combinator.rb +3 -22
  58. data/lib/ludy/z_combinator.rb +2 -16
  59. data/lib/ludy.rb +74 -23
  60. data/lib/puzzle_generator/chain.rb +2 -2
  61. data/lib/puzzle_generator/chained_map.rb +7 -10
  62. data/lib/puzzle_generator/colored_map.rb +2 -2
  63. data/lib/puzzle_generator/map.rb +8 -12
  64. data/lib/puzzle_generator/misc.rb +5 -4
  65. data/lib/puzzle_generator/puzzle.rb +4 -4
  66. data/lib/puzzle_generator.rb +2 -2
  67. data/spec/ludy_spec.rb +22 -0
  68. data/tasks/annotations.rake +30 -0
  69. data/tasks/doc.rake +50 -0
  70. data/tasks/gem.rake +89 -0
  71. data/tasks/manifest.rake +41 -0
  72. data/tasks/rubyforge.rake +57 -0
  73. data/tasks/setup.rb +151 -0
  74. data/tasks/spec.rake +40 -0
  75. data/tasks/svn.rake +44 -0
  76. data/tasks/test.rake +40 -0
  77. data/test/deprecated/callstack.rb +18 -0
  78. data/test/deprecated/curry.rb +34 -0
  79. data/test/deprecated/rambda.rb +15 -0
  80. data/test/{tc_this.rb → deprecated/this.rb} +2 -18
  81. data/test/{ts_ludy.rb → deprecated/ts_ludy.rb} +2 -17
  82. data/test/deprecated/unzip_and_untranspose.rb +13 -0
  83. data/test/{test_puzzle.rb → example_puzzle.rb} +3 -2
  84. data/test/test_all.rb +21 -0
  85. data/test/test_array.rb +47 -0
  86. data/test/test_class.rb +13 -0
  87. data/test/test_defun.rb +37 -0
  88. data/test/test_dices.rb +32 -0
  89. data/test/test_kernel.rb +36 -0
  90. data/test/test_lazy.rb +18 -0
  91. data/test/test_proc.rb +57 -0
  92. data/test/test_symbol.rb +15 -0
  93. data/test/test_variable.rb +29 -0
  94. data/test/test_y_combinator.rb +21 -0
  95. data/test/test_z_combinator.rb +20 -0
  96. metadata +134 -51
  97. data/lib/lib/amulti.rb +0 -40
  98. data/lib/lib/multi.rb +0 -139
  99. data/lib/lib/smulti.rb +0 -56
  100. data/lib/ludy/aspect.rb +0 -41
  101. data/lib/ludy/bind.rb +0 -31
  102. data/lib/ludy/callstack.rb +0 -39
  103. data/lib/ludy/curry.rb +0 -49
  104. data/lib/ludy/ludy_ext.rb +0 -145
  105. data/lib/ludy/rambda.rb +0 -42
  106. data/lib/ludy/this.rb +0 -34
  107. data/ludy.gemspec +0 -44
  108. data/test/tc_bind.rb +0 -29
  109. data/test/tc_callstack.rb +0 -34
  110. data/test/tc_curry.rb +0 -51
  111. data/test/tc_dice.rb +0 -48
  112. data/test/tc_lazy.rb +0 -34
  113. data/test/tc_ludy_ext.rb +0 -154
  114. data/test/tc_rambda.rb +0 -31
  115. data/test/tc_variable.rb +0 -45
  116. data/test/tc_y_combinator.rb +0 -37
  117. data/test/tc_z_combinator.rb +0 -36
@@ -0,0 +1,49 @@
1
+
2
+ module Kernel
3
+
4
+ # just like attr_accessor for c++
5
+ def accessor type, *pros
6
+ (reader_only type, *pros) +
7
+ (writer_only type, *pros) +
8
+ (member_only type, *pros)
9
+ end
10
+
11
+ # just like attr_reader for c++
12
+ def reader type, *pros
13
+ (reader_only type, *pros) +
14
+ (member_only type, *pros)
15
+ end
16
+
17
+ # just like attr_writer for c++
18
+ def writer type, *pros
19
+ (writer_only type, *pros) +
20
+ (member_only type, *pros)
21
+ end
22
+
23
+ # create only reader(getter), no member and no writer(setter)
24
+ def reader_only type, *pros
25
+ result = "#{@prefix}public:\n"
26
+ pros.each{ |p|
27
+ # getter
28
+ result << "#{@prefix}#{@indent}#{type} #{p}() const{ return #{p}_; }\n"
29
+ }
30
+ result
31
+ end
32
+
33
+ # create only writer(setter), no member and no reader(getter)
34
+ def writer_only type, *pros
35
+ result = "#{@prefix}public:\n"
36
+ pros.each{ |p|
37
+ # setter
38
+ result << "#{@prefix}#{@indent}#{@class}& #{p}(#{type} const& new_#{p}){ #{p}_ = new_#{p}; return *this; }\n"
39
+ }
40
+ result
41
+ end
42
+
43
+ # create only member, no writer(setter) and no reader(getter)
44
+ def member_only type, *pros
45
+ result = "#{@prefix}private:\n"
46
+ result << "#{@prefix}#{@indent}#{type} #{pros.map{|p|"#{p}_"}.join(", ")};\n"
47
+ end
48
+
49
+ end # of ludy
@@ -0,0 +1,12 @@
1
+
2
+ module Kernel
3
+
4
+ # C/C++ header guard generator, you shold provide the final #endif yourself,
5
+ # and you should provide PROJ name for header guard prefix
6
+ def header_guard random_suffix = nil
7
+ defined = "_#{PROJ.upcase}_#{@dir.upcase}_#{@class.upcase}_#{random_suffix.nil? ? '' : rand.to_s[2..-1]+'_'}"
8
+ "#ifndef #{defined}
9
+ #define #{defined}"
10
+ end
11
+
12
+ end # of ludy
@@ -0,0 +1,43 @@
1
+
2
+ require 'ludy/array/combos'
3
+
4
+ module Kernel
5
+
6
+ # forward template functions' generator
7
+ def for_template_parameters_within range, modifiers = ['volatile', 'const volatile']
8
+ modifiers = ['', 'const'] + modifiers
9
+ range.to_a.map_with_index{ |size, i|
10
+ ([(["T"]*modifiers.size).zip(
11
+ modifiers,
12
+ ['&']*modifiers.size)]*size).
13
+ map_with_index{ |args, arg_i|
14
+ args.map{ |arg|
15
+ # e.g., T0 const& a
16
+ "#{arg.first}#{arg_i} #{arg.tail.join} #{(arg_i+10).to_s(36)}"
17
+ }
18
+ }.combos.map{ |arg| arg.kind_of?(Array) ? arg.join(', ') : arg }
19
+ }.flatten.each{ |args_list| yield args_list }
20
+ end
21
+
22
+ # parameter for template
23
+ def template_parameters args_list
24
+ size = args_list.count(',') + 1
25
+ '<' + (['class T']*size).map_with_index{ |t, index|
26
+ "#{t}#{index}"
27
+ }.join(', ') + '>'
28
+ end
29
+
30
+ # the parameters' list
31
+ def forward_parameters args_list
32
+ args_list
33
+ end
34
+
35
+ # the arguments it passed
36
+ def arguments args_list
37
+ size = args_list.count(',') + 1
38
+ Array.new(size).map_with_index{ |not_important, i|
39
+ (i+10).to_s 36
40
+ }.join(', ')
41
+ end
42
+
43
+ end # of ludy
@@ -0,0 +1,35 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake/clean'
4
+ require 'ludy'
5
+ Ludy.require_all_in 'tasks/erb_cpp'
6
+
7
+ namespace :erb do
8
+
9
+ inputs = FileList['**/*.erb']
10
+ outputs = inputs.ext
11
+ CLEAN.include outputs
12
+
13
+ desc 'automaticly translate all *.cpp.erb into *.cpp'
14
+ task :preprocess => [:begin, outputs, :end].flatten
15
+ task :begin do; puts "processing templates: #{inputs.inspect}\n\n"; end
16
+ task :end do; puts "processing done."; end
17
+
18
+ require 'erb'
19
+ require 'open-uri'
20
+
21
+ inputs.zip(outputs).each{ |input, output|
22
+ file output => input do
23
+ puts "processing... #{output}"
24
+ open output, 'w' do |o|
25
+ @class = output.pathmap '%n'
26
+ @dir = output.pathmap('%-1d')
27
+ @indent = ' '
28
+ @prefix = ''
29
+ PROJ ||= 'please_set_PROJ_for_your_header_name'
30
+ o << ERB.new(open(input).read).result(binding)
31
+ end
32
+ end
33
+ }
34
+
35
+ end # of namespace erb
data/lib/ludy/tasks.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require 'ludy'
3
+ Ludy.require_all_in 'tasks'
@@ -0,0 +1,3 @@
1
+
2
+ require 'test/unit'
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'ludy')
data/lib/ludy/variable.rb CHANGED
@@ -1,35 +1,27 @@
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.
1
+
2
+ require 'ludy/kernel/public_send'
3
+ require 'ludy/class/undef_all_methods'
16
4
 
17
5
  module Ludy
18
6
 
7
+ # a variable reference, used for side effect...
19
8
  class Variable
20
- instance_methods.each{|m| undef_method m unless m =~ /^__/}
9
+ undef_all_methods
21
10
 
11
+ # init the refered instance
22
12
  def initialize obj
23
13
  @__obj__ = obj
24
14
  end
25
15
 
16
+ # delegator
26
17
  def method_missing msg, *arg, &block
27
- @__obj__.__send__ msg, *arg, &block
18
+ @__obj__.public_send msg, *arg, &block
28
19
  end
29
20
 
30
21
  attr_accessor :__obj__
31
22
  end
32
23
 
24
+ # provided for creating lazy object more convient
33
25
  def var arg
34
26
  Variable.new arg
35
27
  end
@@ -1,30 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
 
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
- begin
18
- require_ludy 'lazy'
19
- rescue NameError
20
- require(File.join(File.dirname(__FILE__), '../', 'ludy'))
21
- require_ludy 'lazy'
22
- end
2
+ require 'ludy/lazy'
23
3
 
24
4
  module Ludy
25
5
 
6
+ # the Y combinator, with lazy stuff
26
7
  Y = lambda{|f|
27
8
  lambda{|x| lazy{f[x[x]]} }[lambda{|x| lazy{f[x[x]]} }]
28
9
  }
29
10
 
30
- end
11
+ end # of Ludy
@@ -1,25 +1,11 @@
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
1
 
17
2
  module Ludy
18
3
 
4
+ # the Z combinator, without lazy stuff
19
5
  Z = lambda{|f|
20
6
  lambda{|x| f[lambda{|y| x[x][y]}]}[
21
7
  lambda{|x| f[lambda{|y| x[x][y]}]}
22
8
  ]
23
9
  }
24
10
 
25
- end
11
+ end # of Ludy
data/lib/ludy.rb CHANGED
@@ -1,23 +1,74 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright (c) 2007, Lin Jen-Shin�]a.k.a. godfat �u�`�^
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
- def require_ludy target = nil
18
- if target
19
- require(File.join(File.dirname(__FILE__), 'ludy', target))
20
- else
21
- require_all_in_dir __FILE__, 'ludy'
22
- end
23
- end
1
+ # $Id$
2
+
3
+ # Equivalent to a header guard in C/C++
4
+ # Used to prevent the class/module from being loaded more than once
5
+ unless defined? LudyHeaderGuard
6
+ module LudyHeaderGuard # :nodoc:
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'rake'
11
+
12
+ module Ludy
13
+
14
+ # :stopdoc:
15
+ VERSION = '0.1.0'
16
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
17
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
18
+ $LOAD_PATH << LIBPATH
19
+ # :startdoc:
20
+
21
+ # Returns the version string for the library.
22
+ #
23
+ def self.version
24
+ VERSION
25
+ end
26
+
27
+ # Returns the library path for the module. If any arguments are given,
28
+ # they will be joined to the end of the libray path using
29
+ # <tt>File.join</tt>.
30
+ #
31
+ def self.libpath( *args )
32
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
33
+ end
34
+
35
+ # Returns the lpath for the module. If any arguments are given,
36
+ # they will be joined to the end of the path using
37
+ # <tt>File.join</tt>.
38
+ #
39
+ def self.path( *args )
40
+ args.empty? ? PATH : ::File.join(PATH, *args)
41
+ end
42
+
43
+ # Utility method used to rquire all files ending in .rb that lie in the
44
+ # directory below this file that has the same name as the filename passed
45
+ # in. Optionally, a specific _directory_ name can be passed in such that
46
+ # the _filename_ does not have to be equivalent to the directory.
47
+ #
48
+ def self.require_all_libs_relative_to( fname, dir = nil )
49
+ dir ||= ::File.basename(fname, '.*')
50
+ search_me = ::File.expand_path(
51
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
52
+
53
+ Dir.glob(search_me).sort.each {|rb| require rb}
54
+ end
55
+
56
+ # require all files in the dir, only work for ludy.
57
+ # i.e., Ludy.require_all_in 'proc' => require 'ludy/proc/*.rb'
58
+ def self.require_all_in dir
59
+ Dir.glob("#{LIBPATH}ludy/#{dir}/*.rb").each{ |i|
60
+ require(if dir == '.'
61
+ i.pathmap('ludy/%n')
62
+ else
63
+ i.pathmap("ludy/#{dir}/%n")
64
+ end)
65
+ }
66
+ end
67
+
68
+ end # module Ludy
69
+
70
+ # Ludy.require_all_libs_relative_to __FILE__
71
+
72
+ end # unless defined?
73
+
74
+ # EOF
@@ -1,9 +1,9 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), 'misc')
2
+ require 'puzzle_generator/misc'
3
3
 
4
4
  module PuzzleGenerator
5
5
 
6
- class Chain
6
+ class Chain # :nodoc:
7
7
  include Enumerable
8
8
  def initialize position = [0, 0], direct = Up, invoke = DefaultOption[:invoke]
9
9
  @direct = direct
@@ -1,16 +1,13 @@
1
1
 
2
- pwd = File.dirname __FILE__
2
+ require 'puzzle_generator/misc'
3
+ require 'puzzle_generator/chain'
4
+ require 'puzzle_generator/map'
3
5
 
4
- require File.join(pwd, 'misc')
5
- require File.join(pwd, 'chain')
6
- require File.join(pwd, 'map')
6
+ require 'ludy/array/combine'
7
7
 
8
8
  require 'rubygems'
9
-
10
- gem 'ludy', '>=0.0.7' # for Array#combine
11
- require 'ludy/ludy_ext'
12
-
13
- gem 'facets', '>=2.0.0' # for lots of things
9
+ gem 'facets', '>=2.0.0'
10
+ require 'facets/enumerable/combos'
14
11
  require 'facets/random' # for Array#pick
15
12
 
16
13
  module PuzzleGenerator
@@ -22,7 +19,7 @@ module PuzzleGenerator
22
19
  # 2. c. check if the position + direct is ok? ok pass, failed choose again
23
20
  # 2. d. goto 2
24
21
 
25
- class ChainedMap
22
+ class ChainedMap # :nodoc:
26
23
  include DisplayMap, MapUtils
27
24
  attr_reader :maps, :option
28
25
  def initialize option = {}
@@ -1,8 +1,8 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), 'misc')
2
+ require 'puzzle_generator/misc'
3
3
 
4
4
  module PuzzleGenerator
5
- class ColoredMap
5
+ class ColoredMap # :nodoc:
6
6
  include DisplayMap, MapUtils
7
7
  def initialize chained_map, colors = (1..chained_map.option[:colors]).to_a
8
8
  @result_map = []
@@ -1,16 +1,12 @@
1
1
 
2
- pwd = File.dirname __FILE__
3
-
4
- require File.join(pwd, 'misc')
5
- require File.join(pwd, 'chain')
2
+ require 'puzzle_generator/misc'
3
+ require 'puzzle_generator/chain'
4
+ require 'ludy/array/body'
6
5
 
7
6
  require 'rubygems'
8
-
9
- gem 'ludy', '>=0.0.7' # for Array#untranspose
10
- require 'ludy/ludy_ext'
11
-
12
- gem 'facets', '>=2.0.0' # for lots of things
13
- require 'facets' # for Array#combos
7
+ gem 'facets', '>=2.0.0'
8
+ require 'facets/enumerable/combos'
9
+ require 'facets/enumerable/uniq_by'
14
10
  require 'facets/random' # for Kernel#maybe
15
11
 
16
12
  # a = [[1,2],[3,4],[5,6]]
@@ -19,7 +15,7 @@ require 'facets/random' # for Kernel#maybe
19
15
 
20
16
  module PuzzleGenerator
21
17
 
22
- class Map
18
+ class Map # :nodoc:
23
19
  include DisplayMap, Enumerable
24
20
  attr_reader :chains
25
21
  def result_map; @data; end
@@ -48,7 +44,7 @@ module PuzzleGenerator
48
44
  def each_column; @data.each{ |column| yield column }; end
49
45
  def clone_with_map
50
46
  Map.new @option.merge(
51
- :data => @data.transpose.map{ |row| row.map{ |i| yield i } }.untranspose,
47
+ :data => @data.transpose.map{ |row| row.map{ |i| yield i } }.transpose,
52
48
  :chains => chains
53
49
  )
54
50
  end
@@ -1,26 +1,27 @@
1
1
 
2
2
  require 'rubygems'
3
- require 'facets' # for Array#deep_clone
4
- # require 'ludy/ludy_ext' # for Kernel#curry
3
+ require 'facets/kernel/deep_clone'
4
+ require 'facets/array/pad'
5
5
 
6
6
  module PuzzleGenerator
7
7
  Up, Right, Left = (0..2).to_a
8
8
  DefaultOption = {:width => 6, :height => 10, :level => 4, :colors => 4,
9
9
  :invoke => 3, :invoke_max => 5, :timeout => 5}
10
+ # whenever the generation is falied, this exception would raise
10
11
  class GenerationFailed < RuntimeError; end
11
12
  class << self
12
13
  attr_writer :debug
13
14
  def debug; @debug || false; end
14
15
  end
15
16
 
16
- module DisplayMap
17
+ module DisplayMap # :nodoc:
17
18
  attr_reader :result_map
18
19
  def display_map
19
20
  result_map.transpose.reverse_each{ |row| puts row.map{ |color| '%2d' % color }.join(' ') }
20
21
  end
21
22
  end
22
23
 
23
- module MapUtils
24
+ module MapUtils # :nodoc:
24
25
  def make_map_array; (Array.new(@option[:width])).map{ [0]*@option[:height] }; end
25
26
  def resolve_map result_map = @result_map, maps = @maps
26
27
  result_map.replace maps.inject(make_map_array){ |result, map|
@@ -1,10 +1,10 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), 'misc')
3
- require File.join(File.dirname(__FILE__), 'chained_map')
4
- require File.join(File.dirname(__FILE__), 'colored_map')
2
+ require 'puzzle_generator/misc'
3
+ require 'puzzle_generator/chained_map'
4
+ require 'puzzle_generator/colored_map'
5
5
 
6
6
  require 'rubygems'
7
- require 'facets' # for Array#rotate
7
+ require 'facets/array/rotate'
8
8
  require 'facets/timer'
9
9
 
10
10
  module PuzzleGenerator
@@ -1,10 +1,10 @@
1
1
 
2
2
  # alpha at 2007.10.14
3
3
 
4
- require File.join(File.dirname(__FILE__), 'puzzle_generator', 'puzzle')
4
+ require 'puzzle_generator/puzzle'
5
5
 
6
6
  require 'rubygems'
7
- require 'facets' # for Hash#reverse_merge
7
+ require 'facets/hash/reverse_merge'
8
8
  require 'facets/timer'
9
9
 
10
10
  module PuzzleGenerator
data/spec/ludy_spec.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ # bowling.rb
3
+ class Bowling
4
+ def hit(pins)
5
+ end
6
+
7
+ def score
8
+ 0
9
+ end
10
+ end
11
+
12
+ # bowling_spec.rb
13
+ describe Bowling do
14
+ before(:each) do
15
+ @bowling = Bowling.new
16
+ end
17
+
18
+ it "should score 0 for gutter game" do
19
+ 20.times { @bowling.hit(0) }
20
+ @bowling.score.should == 0
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ desc "Enumerate all annotations"
6
+ task :notes do
7
+ Bones::AnnotationExtractor.enumerate(
8
+ PROJ, "OPTIMIZE|FIXME|TODO", :tag => true)
9
+ end
10
+
11
+ namespace :notes do
12
+ desc "Enumerate all OPTIMIZE annotations"
13
+ task :optimize do
14
+ Bones::AnnotationExtractor.enumerate(PROJ, "OPTIMIZE")
15
+ end
16
+
17
+ desc "Enumerate all FIXME annotations"
18
+ task :fixme do
19
+ Bones::AnnotationExtractor.enumerate(PROJ, "FIXME")
20
+ end
21
+
22
+ desc "Enumerate all TODO annotations"
23
+ task :todo do
24
+ Bones::AnnotationExtractor.enumerate(PROJ, "TODO")
25
+ end
26
+ end
27
+
28
+ end # if HAVE_BONES
29
+
30
+ # EOF
data/tasks/doc.rake ADDED
@@ -0,0 +1,50 @@
1
+ # $Id$
2
+
3
+ require 'rake/rdoctask'
4
+
5
+ namespace :doc do
6
+
7
+ desc 'Generate RDoc documentation'
8
+ Rake::RDocTask.new do |rd|
9
+ rd.main = PROJ.rdoc_main
10
+ rd.options << '-d' if !WIN32 and `which dot` =~ %r/\/dot/
11
+ rd.rdoc_dir = PROJ.rdoc_dir
12
+
13
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
14
+ excl = Regexp.new(PROJ.rdoc_exclude.join('|'))
15
+ files = PROJ.files.find_all do |fn|
16
+ case fn
17
+ when excl; false
18
+ when incl; true
19
+ else false end
20
+ end
21
+ rd.rdoc_files.push(*files)
22
+
23
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
24
+ title = "#{PROJ.rubyforge_name}'s " + title if PROJ.rubyforge_name != title
25
+
26
+ rd.options << "-t #{title}"
27
+ rd.options << '--charset=utf-8' << '--inline-source' << '--line-numbers'
28
+ end
29
+
30
+ desc 'Generate ri locally for testing'
31
+ task :ri => :clobber_ri do
32
+ sh "#{RDOC} --ri -o ri ."
33
+ end
34
+
35
+ desc 'Remove ri products'
36
+ task :clobber_ri do
37
+ rm_r 'ri' rescue nil
38
+ end
39
+
40
+ end # namespace :doc
41
+
42
+ desc 'Alias to doc:rdoc'
43
+ task :doc => 'doc:rdoc'
44
+
45
+ desc 'Remove all build products'
46
+ task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
47
+
48
+ remove_desc_for_task %w(doc:clobber_rdoc doc:clobber_ri)
49
+
50
+ # EOF