Skip to content

Commit

Permalink
Merge pull request #688 from Shopify/match
Browse files Browse the repository at this point in the history
Use `String#match?` over `String#=~` when applicable
  • Loading branch information
tenderlove authored Sep 24, 2024
2 parents 786a8dd + b2d9f16 commit ac15c01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def accept target

unless @domain_types.empty? || !target.tag
key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
key = "tag:#{key}" unless key.match?(/^(?:tag:|x-private)/)

if @domain_types.key? key
value, block = @domain_types[key]
Expand Down
6 changes: 3 additions & 3 deletions lib/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def visit_String o
style = Nodes::Scalar::LITERAL
plain = false
quote = false
elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
elsif o.match?(/\n(?!\Z)/) # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
Expand All @@ -272,9 +272,9 @@ def visit_String o
style = Nodes::Scalar::DOUBLE_QUOTED
elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/
elsif o.match?(/^[^[:word:]][^"]*$/)
style = Nodes::Scalar::DOUBLE_QUOTED
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/.match?(o)
style = Nodes::Scalar::SINGLE_QUOTED
end

Expand Down

0 comments on commit ac15c01

Please sign in to comment.