From 1277be4dbeb50d0eb23982b61174f22d7aafcdfe Mon Sep 17 00:00:00 2001 From: chaymaeBZ Date: Tue, 26 Nov 2024 21:41:08 +0100 Subject: [PATCH] Use `tr` instead of `gsub` `tr` is cheaper to run than `gsub` --- lib/generators/stimulus/stimulus_generator.rb | 2 +- lib/stimulus/manifest.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/stimulus/stimulus_generator.rb b/lib/generators/stimulus/stimulus_generator.rb index 5af2437..80e1e2f 100644 --- a/lib/generators/stimulus/stimulus_generator.rb +++ b/lib/generators/stimulus/stimulus_generator.rb @@ -17,6 +17,6 @@ def controller_name end def stimulus_attribute_value(controller_name) - controller_name.gsub(/\//, "--").gsub("_", "-") + controller_name.gsub(/\//, "--").tr("_", "-") end end diff --git a/lib/stimulus/manifest.rb b/lib/stimulus/manifest.rb index 709e594..c22137b 100644 --- a/lib/stimulus/manifest.rb +++ b/lib/stimulus/manifest.rb @@ -13,7 +13,7 @@ def import_and_register_controller(controllers_path, controller_path) controller_path = controller_path.relative_path_from(controllers_path).to_s module_path = controller_path.split('.').first controller_class_name = module_path.underscore.camelize.gsub(/::/, "__") - tag_name = module_path.remove(/_controller/).gsub(/_/, "-").gsub(/\//, "--") + tag_name = module_path.remove(/_controller/).tr("_", "-").gsub(/\//, "--") <<-JS