Skip to content

Commit

Permalink
Replace Ruby Hash#key to Crystal Hash#key_for
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Nov 15, 2024
1 parent ae77ff7 commit 91a84bb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/port_ruby_to_crystal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def replace(code)
code.gsub!(/require ('|")fileutils(\k<1>)$/, 'require "file_utils"')
code.gsub!(/\.include\?(\s*)/, '.includes?\1')
code.gsub!(/\.end_with\?(\s*)/, '.ends_with?\1')
code.gsub!(/\.key\(/, '.key_for(')
code.gsub!(/\.start_with\?(\s*)/, '.starts_with?\1')
code.gsub!(/(\w+\[.*?\]) (\|\||&&)(?!=)/, '\1? \2')
code.gsub!(/\battr_accessor\b/, 'property')
Expand Down
1 change: 1 addition & 0 deletions test/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ arr = {"foo1" => "bar1"}
arr["foo2"]? || "bar2"
arr["foo3"] ||= "bar3"
arr["foo1"]? && "ok"
arr.key_for("bar1")

["hello", "world"].includes? "hello"

Expand Down
1 change: 1 addition & 0 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
arr["foo2"] || "bar2"
arr["foo3"] ||= "bar3"
arr["foo1"] && "ok"
arr.key("bar1")

["hello", "world"].include? "hello"

Expand Down

0 comments on commit 91a84bb

Please sign in to comment.