Class: Pathname
Instance Method Summary collapse
- #_original_sub ⇒ Object
-
#find_up(rel_path, **kwds) ⇒ Object
See NRSER.find_up.
-
#find_up!(rel_path, **kwds) ⇒ Object
See NRSER.find_up!.
-
#start_with?(*prefixes) ⇒ Boolean
override to accept Pathname instances.
-
#sub(pattern, replacement) ⇒ Pathname
override sub to support Pathname instances as patterns.
-
#to_dot_rel(**kwds) ⇒ Pathname
Shortcut to call #to_rel with ‘dot_slash=true`.
-
#to_dot_rel_s(**kwds) ⇒ String
Shortcut to call #to_rel_s with ‘dot_slash=true`.
-
#to_pn ⇒ Pathname
Just returns ‘self`.
-
#to_rel(base_dir: Pathname.getwd, dot_slash: false) ⇒ Pathname
Shortcut to convert into a relative pathname, by default from the working directory, with option to ‘./` prefix.
-
#to_rel_s(**kwds) ⇒ String
Just a quick cut for ‘.to_rel.to_s`, since I seem to use that sort of form a lot.
Instance Method Details
#_original_sub ⇒ Object
24 |
# File 'lib/nrser/core_ext/pathname.rb', line 24 alias_method :_original_sub, :sub |
#find_up(rel_path, **kwds) ⇒ Object
See NRSER.find_up.
60 61 62 |
# File 'lib/nrser/core_ext/pathname.rb', line 60 def find_up rel_path, **kwds NRSER.find_up rel_path, **kwds, from: self end |
#find_up!(rel_path, **kwds) ⇒ Object
See NRSER.find_up!.
67 68 69 |
# File 'lib/nrser/core_ext/pathname.rb', line 67 def find_up! rel_path, **kwds NRSER.find_up! rel_path, **kwds, from: self end |
#start_with?(*prefixes) ⇒ Boolean
override to accept Pathname instances.
13 14 15 16 17 18 19 20 21 |
# File 'lib/nrser/core_ext/pathname.rb', line 13 def start_with? *prefixes to_s.start_with? *prefixes.map { |prefix| if Pathname === prefix prefix.to_s else prefix end } end |
#sub(pattern, replacement) ⇒ Pathname
override sub to support Pathname instances as patterns.
38 39 40 41 42 43 44 45 |
# File 'lib/nrser/core_ext/pathname.rb', line 38 def sub pattern, replacement case pattern when Pathname _original_sub pattern.to_s, replacement else _original_sub pattern, replacement end end |
#to_dot_rel(**kwds) ⇒ Pathname
Shortcut to call #to_rel with ‘dot_slash=true`.
100 101 102 |
# File 'lib/nrser/core_ext/pathname.rb', line 100 def to_dot_rel **kwds to_rel **kwds, dot_slash: true end |
#to_dot_rel_s(**kwds) ⇒ String
Shortcut to call #to_rel_s with ‘dot_slash=true`.
122 123 124 |
# File 'lib/nrser/core_ext/pathname.rb', line 122 def to_dot_rel_s **kwds to_rel_s( **kwds, dot_slash: true ).to_s end |
#to_pn ⇒ Pathname
Just returns ‘self`. Implemented to match the String#to_pn API so it can be called on an argument that may be either one.
53 54 55 |
# File 'lib/nrser/core_ext/pathname.rb', line 53 def to_pn self end |
#to_rel(base_dir: Pathname.getwd, dot_slash: false) ⇒ Pathname
Shortcut to convert into a relative pathname, by default from the working directory, with option to ‘./` prefix.
84 85 86 87 88 89 90 91 92 |
# File 'lib/nrser/core_ext/pathname.rb', line 84 def to_rel base_dir: Pathname.getwd, dot_slash: false rel = relative_path_from base_dir if dot_slash && !rel.start_with?( /\.\.?\// ) File.join( '.', rel ).to_pn else rel end end |
#to_rel_s(**kwds) ⇒ String
Just a quick cut for ‘.to_rel.to_s`, since I seem to use that sort of form a lot.
112 113 114 |
# File 'lib/nrser/core_ext/pathname.rb', line 112 def to_rel_s **kwds to_rel( **kwds ).to_s end |