def user_path(path)
pre = $user_remote_pictures_paths[digest(path, $user_remote_pictures_paths.length)]
"#{pre}/#{path}"
end
def network_path(path)
pre = $network_remote_pictures_paths[digest(path, $network_remote_pictures_paths.length)]
"#{pre}/#{path}"
end
def thumbnail_path(path)
pre = $thumbnail_remote_pictures_paths[digest(path, $thumbnail_remote_pictures_paths.length)]
"#{pre}/#{path}"
end
Refactorings
No refactoring yet !
danielharan
August 8, 2008, August 08, 2008 19:32, permalink
The two last methods don't actually use pre? And what's the rationale for line 2???
incrediblybuilt.myopenid.com
August 8, 2008, August 08, 2008 19:46, permalink
Sorry, that's my mistake. Edited. I could make it all one line, but thought that was super hard to read.
Ethan Vizitei
August 8, 2008, August 08, 2008 21:23, permalink
Here's my input, for what it's worth. It's a little longer, but moves the shared functionality into one place:
def user_path(path)
path_template $user_remote_pictures_paths,path
end
def network_path(path)
path_template $network_remote_pictures_paths,path
end
def thumbnail_path(path)
path_template $thumbnail_remote_pictures_paths,path
end
def path_template(global,path)
"#{global[digest(path, global.length)]}/#{path}"
end
Maciej Piechotka
August 8, 2008, August 08, 2008 21:39, permalink
May be something like that:
PS. Usage of global variables is not recommended.
%w{user network thumbnail}.each do |obj|
module_eval <<-"EOS", __FILE__, __LINE__
def #{obj}_path(path)
rpp = $#{obj}_remote_pictures_paths
pre = rpp[digest(path, rpp.length)]
"\#{pre}/\#{path}"
end
EOS
end
leemic
August 12, 2008, August 12, 2008 06:25, permalink
You may want to use 'File.join' instead "#{pre}/#{path}" in case you may want to run other than Unix
File.join( pre, path )
It's ugly, yes..