Method: ChefUtils::VersionString#=~

Defined in:
lib/chef-utils/version_string.rb

#=~(other) ⇒ Boolean

Matching operator to support checking against a requirement string.

Examples:

Match against a Regexp

ChefUtils::VersionString.new('1.0.0') =~ /^1/

Match against a requirement

ChefUtils::VersionString.new('1.0.0') =~ '~> 1.0'

Parameters:

  • other (Regexp, String)

Returns:

  • (Boolean)

Since:

  • 13.2



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/chef-utils/version_string.rb', line 138

def =~(other)
  case other
  when Regexp
    super
  else
    begin
      Gem::Requirement.create(other) =~ parsed_version
    rescue ArgumentError
      # one side of the comparison wasn't parsable
      super
    end
  end
end