D41d8cd98f00b204e9800998ecf8427e

It's ugly, yes..

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 !

880cbab435f00197613c9cc2065b4f5a

danielharan

August 8, 2008, August 08, 2008 19:32, permalink

No rating. Login to rate!

The two last methods don't actually use pre? And what's the rationale for line 2???

D41d8cd98f00b204e9800998ecf8427e

incrediblybuilt.myopenid.com

August 8, 2008, August 08, 2008 19:46, permalink

No rating. Login to rate!

Sorry, that's my mistake. Edited. I could make it all one line, but thought that was super hard to read.

Bcd21effa8174ab2f4fd69d448e82e87

Ethan Vizitei

August 8, 2008, August 08, 2008 21:23, permalink

No rating. Login to rate!

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
1e8f141e7857d397d8020ed3b759e88a

Maciej Piechotka

August 8, 2008, August 08, 2008 21:39, permalink

No rating. Login to rate!

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
D41d8cd98f00b204e9800998ecf8427e

leemic

August 12, 2008, August 12, 2008 06:25, permalink

No rating. Login to rate!

You may want to use 'File.join' instead "#{pre}/#{path}" in case you may want to run other than Unix

File.join( pre, path )

Your refactoring





Format Copy from initial code

or Cancel