Class: Hanami::Utils::PathPrefix
- Defined in:
- gems/gems/hanami-utils-2.2.0.beta1/lib/hanami/utils/path_prefix.rb
Overview
Prefixed string
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
(also: #eql?)
Equality.
-
#hash ⇒ Integer
Returns the hash of the internal string.
-
#initialize(string = nil, separator = DEFAULT_SEPARATOR) ⇒ PathPrefix
constructor
Initialize the path prefix.
-
#join(*strings) ⇒ Hanami::Utils::PathPrefix
Joins self with the given token.
-
#relative_join(strings, separator = @separator) ⇒ Hanami::Utils::PathPrefix
Joins self with the given token, without prefixing it with
separator
. -
#to_s ⇒ ::String
(also: #to_str)
Returns a string representation.
Constructor Details
#initialize(string = nil, separator = DEFAULT_SEPARATOR) ⇒ PathPrefix
Initialize the path prefix
Source: | on GitHub
def initialize(string = nil, separator = DEFAULT_SEPARATOR) @string = string.to_s @separator = separator end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass Also known as: eql?
Equality
Source: | on GitHub
def ==(other) to_s == other end |
#hash ⇒ Integer
Returns the hash of the internal string
Source: | on GitHub
def hash @string.hash end |
#join(*strings) ⇒ Hanami::Utils::PathPrefix
Joins self with the given token. It cleans up all the separator
repetitions.
Source: | on GitHub
def join(*strings) relative_join(strings).absolute! end |
#relative_join(strings, separator = @separator) ⇒ Hanami::Utils::PathPrefix
Joins self with the given token, without prefixing it with separator
. It cleans up all the separator
repetitions.
Source: | on GitHub
def relative_join(strings, separator = @separator) raise TypeError if separator.nil? prefix = @string.gsub(@separator, separator) result = [prefix, strings] result.flatten! result.compact! result.reject! { |string| string == separator } self.class.new( result.join(separator), separator ).relative! end |