diff options
author | lifo <lifo@null.lan> | 2009-04-17 14:28:46 +0100 |
---|---|---|
committer | lifo <lifo@null.lan> | 2009-04-17 14:28:46 +0100 |
commit | 5b92dcb6757e90da316bd0c7a8472b9fa737f268 (patch) | |
tree | 6893d7cff5e18862f2c419588656600a4dec1090 /railties/guides/rails_guides | |
parent | abb899c54e8777428b7a607774370ba29a5573bd (diff) | |
download | rails-5b92dcb6757e90da316bd0c7a8472b9fa737f268.tar.gz rails-5b92dcb6757e90da316bd0c7a8472b9fa737f268.tar.bz2 rails-5b92dcb6757e90da316bd0c7a8472b9fa737f268.zip |
Merge docrails
Diffstat (limited to 'railties/guides/rails_guides')
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 2 | ||||
-rw-r--r-- | railties/guides/rails_guides/levenshtein.rb | 48 |
2 files changed, 26 insertions, 24 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index f93282db2e..2a4714b13a 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -48,7 +48,7 @@ module RailsGuides if guide =~ /\.erb\.textile/ # Generate the erb pages with textile formatting - e.g. index/authors - result = view.render(:layout => 'layout', :file => name) + result = view.render(:layout => 'layout', :file => guide) f.write textile(result) else body = File.read(File.join(view_path, guide)) diff --git a/railties/guides/rails_guides/levenshtein.rb b/railties/guides/rails_guides/levenshtein.rb index 4010b61e26..f99c6e6ba8 100644 --- a/railties/guides/rails_guides/levenshtein.rb +++ b/railties/guides/rails_guides/levenshtein.rb @@ -1,29 +1,31 @@ -module Levenshtein - # Based on the pseudocode in http://en.wikipedia.org/wiki/Levenshtein_distance. - def self.distance(s1, s2) - s = s1.unpack('U*') - t = s2.unpack('U*') - m = s.length - n = t.length +module RailsGuides + module Levenshtein + # Based on the pseudocode in http://en.wikipedia.org/wiki/Levenshtein_distance. + def self.distance(s1, s2) + s = s1.unpack('U*') + t = s2.unpack('U*') + m = s.length + n = t.length - # matrix initialization - d = [] - 0.upto(m) { |i| d << [i] } - 0.upto(n) { |j| d[0][j] = j } + # matrix initialization + d = [] + 0.upto(m) { |i| d << [i] } + 0.upto(n) { |j| d[0][j] = j } - # distance computation - 1.upto(m) do |i| - 1.upto(n) do |j| - cost = s[i] == t[j] ? 0 : 1 - d[i][j] = [ - d[i-1][j] + 1, # deletion - d[i][j-1] + 1, # insertion - d[i-1][j-1] + cost, # substitution - ].min + # distance computation + 1.upto(m) do |i| + 1.upto(n) do |j| + cost = s[i] == t[j] ? 0 : 1 + d[i][j] = [ + d[i-1][j] + 1, # deletion + d[i][j-1] + 1, # insertion + d[i-1][j-1] + cost, # substitution + ].min + end end - end - # all done - return d[m][n] + # all done + return d[m][n] + end end end |