class String

require_relative '../constraints'

Public Instance Methods

flush() click to toggle source

Left-flush a string based off of the number of whitespace characters on the first line. This is especially useful for heredocs when whitespace matters.

@example Remove leading whitespace and flush

<<-EOH.flush
  def method
    'This is a string!'
  end
EOH #=>"def method\n  'This is a string!'\nend"

@return [String]

# File lib/chef/sugar/core_extensions/string.rb, line 63
def flush
  gsub(/^#{self[/\A\s*/]}/, '').chomp
end
satisfied_by?(version) click to toggle source

Treat strings as version constraints.

@see Chef::Sugar::Constraints::Constraint

@example Using pure string objects like constraints

'~> 1.2.0'.satisfied_by?('1.2.3')

@param [String] version

the version to check if it is satisfied
# File lib/chef/sugar/core_extensions/string.rb, line 46
def satisfied_by?(version)
  Chef::Sugar::Constraints::Constraint.new(dup).satisfied_by?(version)
end
satisfies?(*constraints) click to toggle source

Treat strings as version objects.

@see Chef::Sugar::Constraints::Version

@example Using pure string objects like versions

'1.2.3'.satisfies?('~> 1.2.0')

@param [String, Array<String>] constraints

the list of constraints to satisfy
# File lib/chef/sugar/core_extensions/string.rb, line 31
def satisfies?(*constraints)
  Chef::Sugar::Constraints::Version.new(dup).satisfies?(*constraints)
end