Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- Defined in:
- lib/pathname/common_prefix.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.common_prefix(*paths) ⇒ Object
5 6 7 8 9 |
# File 'lib/pathname/common_prefix.rb', line 5 def common_prefix(*paths) return if paths.empty? paths.flatten! Pathname(paths.pop).common_prefix(paths) end |
Instance Method Details
#common_prefix(*others) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/pathname/common_prefix.rb', line 12 def common_prefix(*others) others.flatten! others.map! {|path| Pathname path} enum_for(:ascend).find {|path| others.all?{|other|other.start_with?(path)} } end |
#start_with?(other) ⇒ Boolean
20 21 22 |
# File 'lib/pathname/common_prefix.rb', line 20 def start_with?(other) enum_for(:descend).include?(Pathname(other)) end |