2007/11/14, [email protected] [email protected]:
}
}.as { |data_files|
add_suffixes(source_files + add_prefixes(data_files))
}.map { |basename|
File.join dir, basename
}(BTW ‘suffix’ here means the chars right before the dot; after the dot
I call the extension.)
Why do add_suffixes and add_prefixes have to be methods that work on a
collection instead of a single item? Do they modify the collection in
any way or do they need information from other entries to do their
work on a single entry?
If not, I would change that and then you could do this:
all_files = (
source_files +
stems.map {|stem| add_prefix “#{ stem }.#{ guess_extension stem }”}
).map {|name| File.join dir, add_suffix(name)}
This is still pretty complex (but the algorithm is anyway) and you do
not need any temporaries outside of block parameters. Also,
add_suffix and add_prefix will be relieved from iterating collections
and can be focussed on doing one thing properly.
Kind regards
robert
SCNR