Skip to content

Instantly share code, notes, and snippets.

@rhyhann
Created December 21, 2009 09:42
Show Gist options
  • Save rhyhann/260880 to your computer and use it in GitHub Desktop.
Save rhyhann/260880 to your computer and use it in GitHub Desktop.
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)
<% 8.files me.path, me.path.sub('.erb', '.%N%.erb') do |n| %>
<%= n %>
<% end %>
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