Module: NRSER::Ext::Pathname

Defined in:
lib/nrser/ext/pathname.rb

Instance Method Summary collapse

Instance Method Details

#find_up(rel_path, **kwds) ⇒ return_type

TODO:

Document find_root method.

Returns @todo Document return value.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



57
58
59
# File 'lib/nrser/ext/pathname.rb', line 57

def find_up rel_path, **kwds
  NRSER.find_up rel_path, **kwds, from: self
end

#find_up!(rel_path, **kwds) ⇒ return_type

TODO:

Document find_root method.

Returns @todo Document return value.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



70
71
72
# File 'lib/nrser/ext/pathname.rb', line 70

def find_up! rel_path, **kwds
  NRSER.find_up! rel_path, **kwds, from: self
end

#start_with?(*prefixes) ⇒ Boolean

override to accept Pathname instances.

Parameters:

  • *prefixes (String)

    the prefixes to see if the Pathname starts with.

Returns:

  • (Boolean)

    true if the Pathname starts with any of the prefixes.



13
14
15
# File 'lib/nrser/ext/pathname.rb', line 13

def start_with? *prefixes
  to_s.start_with? *prefixes.map(&:to_s)
end

#sub(pattern, replacement) ⇒ Pathname

override sub to support Pathname instances as patterns.

Parameters:

  • pattern (String | Regexp | Pathname)

    thing to replace.

  • replacement (String | Hash)

    thing to replace it with.

Returns:



29
30
31
32
33
34
35
36
# File 'lib/nrser/ext/pathname.rb', line 29

def sub pattern, replacement
  case pattern
  when Pathname
    super pattern.to_s, replacement
  else
    super pattern, replacement
  end
end

#to_pnPathname

Just returns ‘self`. Implemented to match the String#to_pn API so it can be called on an argument that may be either one.

Returns:



44
45
46
# File 'lib/nrser/ext/pathname.rb', line 44

def to_pn
  self
end