Class: ConvenientService::Utils::String::Enclose Private

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/string/enclose.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Examples:

Common usage.

ConvenientService::Utils::String::Enclose.call("foo", "_")
# => "_foo_"

ConvenientService::Utils::String::Enclose.call("", "_")
# => "_"

ConvenientService::Utils::String::Enclose.call(nil, "_")
# => "_"

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(string, char) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Since:

  • 1.0.0



40
41
42
43
# File 'lib/convenient_service/utils/string/enclose.rb', line 40

def initialize(string, char)
  @string = string
  @char = char
end

Instance Attribute Details

#charObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



33
34
35
# File 'lib/convenient_service/utils/string/enclose.rb', line 33

def char
  @char
end

#stringObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



27
28
29
# File 'lib/convenient_service/utils/string/enclose.rb', line 27

def string
  @string
end

Instance Method Details

#callString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 1.0.0



48
49
50
51
52
53
# File 'lib/convenient_service/utils/string/enclose.rb', line 48

def call
  return char unless string
  return char if string.empty?

  "#{char}#{string}#{char}"
end