RosettaCodeData/Task/Find-common-directory-path/Ruby/find-common-directory-path-1.rb

7 lines
305 B
Ruby
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
require 'abbrev'
dirs = %w( /home/user1/tmp/coverage/test /home/user1/tmp/covert/operator /home/user1/tmp/coven/members )
common_prefix = dirs.abbrev.keys.min_by {|key| key.length}.chop # => "/home/user1/tmp/cove"
2015-02-20 00:35:01 -05:00
common_directory = common_prefix.sub(%r{/[^/]*$}, '') # => "/home/user1/tmp"