forked from ZaneA/XMMSinatra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.rb
More file actions
103 lines (91 loc) · 1.3 KB
/
Copy pathutils.rb
File metadata and controls
103 lines (91 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'rubygems'
require 'superators'
module Enumerable
def split_by_(f)
last = []
last_key = nil
first = true
each do |element|
key = f.call(element)
if first
last_key = key
first = false
end
if last_key == key
last.push(element)
else
yield last_key, last if block_given?
last_key = key
last = [element]
end
end
if !last.empty?
yield last_key, last if block_given?
end
end
def split_by
res = []
last = []
last_key = nil
first = true
each do |element|
key = yield(element)
if first
last_key = key
first = false
end
if last_key == key
last.push element
else
res.push [last_key, last]
last_key = key
last = [element]
end
end
if !last.empty?
res.push [last_key, last]
end
res
end
def common
a = nil
each do |i|
if a == nil
if block_given?
a = yield i
else
a = i
end
else
if block_given?
a &= yield i
else
a &= i
end
end
end
a
end
end
class Object
def _? b
nil? ? b : self
end
end
class String
def path_components
a = self
res = [] if !block_given?
loop {
b, c = File.split(a)
if block_given?
yield(c)
else
res.push(c)
end
break if b == "."
a = b
}
res if !block_given?
end
end