Skip to content

Commit f6928bb

Browse files
committedOct 27, 2014
Add some Pathname methods
1 parent dbc1bd8 commit f6928bb

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed
 

‎spec/rubyspecs

+1-8
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ corelib/language/while_spec
256256

257257
stdlib/rubysl-singleton/spec/
258258
stdlib/rubysl-observer/spec/
259+
stdlib/rubysl-pathname/spec/
259260

260261
stdlib/rubysl-strscan/spec/bol_spec
261262
stdlib/rubysl-strscan/spec/check_spec
@@ -315,14 +316,6 @@ stdlib/rubysl-set/spec/to_a_spec
315316
# stdlib/rubysl-set/spec/superset_spec
316317
# stdlib/rubysl-set/spec/union_spec
317318

318-
319-
320-
321-
stdlib/rubysl-pathname/spec/new_spec
322-
stdlib/rubysl-pathname/spec/equal_value_spec
323-
stdlib/rubysl-pathname/spec/absolute_spec
324-
stdlib/rubysl-pathname/spec/relative_spec
325-
326319
stdlib/rubysl-date/spec/date/add_spec
327320
stdlib/rubysl-date/spec/date/eql_spec
328321
stdlib/rubysl-date/spec/date/minus_spec

‎stdlib/pathname.rb

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Pathname
2-
def initialize path
2+
def initialize(path)
33
raise ArgumentError if path == "\0"
44
@path = path
55
end
@@ -18,14 +18,38 @@ def relative?
1818
!absolute?
1919
end
2020

21+
def root?
22+
@path == '/'
23+
end
24+
25+
def parent
26+
new_path = @path.sub(%r{/([^/]+/?$)}, '')
27+
new_path = absolute? ? '/' : '.' if new_path == ''
28+
Pathname.new(new_path)
29+
end
30+
31+
def sub(*args)
32+
Pathname.new(@path.sub(*args))
33+
end
34+
35+
def cleanpath
36+
`return $opal.normalize_loadable_path(#@path)`
37+
end
38+
2139
def to_path
2240
@path
2341
end
42+
43+
def hash
44+
@path
45+
end
46+
2447
alias :to_str :to_path
2548
alias :to_s :to_path
2649
end
2750

2851
module Kernel
2952
def Pathname(path)
53+
Pathname.new(path)
3054
end
3155
end

0 commit comments

Comments
 (0)
Please sign in to comment.