Created
December 21, 2009 09:42
-
-
Save rhyhann/260880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def files(first_path, glob_path, &block) | |
# With this block, there is no problem. | |
# block = :to_s.to_proc | |
iteration = proc do |num, path| | |
tmppath = "#{Dir.tmpdir}/#{path}" | |
::FileUtils.mkdir_p(::File.dirname(tmppath)) | |
::File.open(tmppath, 'w+') {|f| f.puts(block.call(num))} | |
Battuta::File(tmppath).path = path | |
end | |
iteration[0, first_path] | |
1.upto(self - 1) {|num| iteration[num, glob_path.sub('%N%', num.to_s)]} | |
nil | |
end | |
end | |
me = Battuta::File.new | |
puts ::ERB.new(me.content).result(binding) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 8.files me.path, me.path.sub('.erb', '.%N%.erb') do |n| %> | |
<%= n %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first file: | |
0 | |
second file: | |
0 | |
1 | |
third file: | |
0 | |
1 | |
2 | |
fourth file: | |
0 | |
1 | |
2 | |
3 | |
and so on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment