大éªRubyä¼è°04åãã«ãªãªã¼ã¹ãã Minify Ruby ã«ã¤ãã¦ã¨ãããã¾ãã
ãã£ãããã㨠JavaScript ã® UgilifyJS ã Terser ã®ãããªä½ç½®ä»ãã§ãRuby ã®ã½ã¼ã¹ã³ã¼ãã Minify ãã Gem ã§ãã
使ãæ¹
使ãæ¹ã¯ README.md ã«è¨ãã¦ããã¨ããã§ãããã³ãã³ãã©ã¤ã³ããã§ããã°ãminifyrb
ã³ãã³ããå©ãã®ãã·ã³ãã«ã§ãã
$ gem i minifyrb $ minifyrb path/to/file.rb
ãã㧠minify ãããã³ã¼ããæ¨æºåºåã«åºåããã¾ããecho 'puts :hello' | minifyrb
ã¨ãã£ããã¤ãã§ã®æ¨æºå
¥åããã®ä½¿ãæ¹ãã-o
ãªãã·ã§ã³ã使ã£ããã¡ã¤ã«åºåãå¯è½ã§ãã
ããå°ãå®ç¨ç (ã¨ã¯?) ãªä½¿ãæ¹ã¨ãã¦ã¯ãã¾ã Gemfile ã« minifyrb ã追å ãã¾ãã
# Gemfile gem 'minifyrb'
ç¶ãã¦ãã¤ãã®æµã㧠bundle install
ãå®è¡ã
$ bundle install
次㫠Rakefile ã¸ã®ã¿ã¹ã¯è¿½å ããã¾ãã
# Rakefile require 'minifyrb/rake_task' Minifyrb::RakeTask.new
ããã«ãã£ã¦ bundle exec rake minifyrb
ã§å®è¡ã§ããããã«ãªãã¾ãããã® bundle exec rake minifyrb
ã¯ãã£ã¬ã¯ããªé
ä¸ã® *.rb ãã¡ã¤ã«ã«å¯¾ãã¦ç´æ¥ minify ããã¾ãã®ã§ãgit ãªãã¸ããªã§ç®¡çããã¦ãããã¨ãæ¨å¥¨ãã¾ãã
$ bundle exec rake minifyrb
å°ã大ããªãã®ã§ä½¿ãããå ´åã¯ãããããããã§ããä½è«ã§ãããç§ã大éªRubyä¼è°04ã®çºè¡¨ãã¢ã§ä½¿ã£ã¦ããã³ãã³ãã¯ãã¡ãã«ãªãã¾ãã
対象ã®å¦çç³»
ç¾ç¶ã§ã¯ Ruby 3.3 以ä¸ã®ãã¼ã¹ãè¡ã Prism ãæ§æ解æã®ã¨ã³ã¸ã³ã«ãã¦ããé¢ä¿ã§ãRuby 3.3 以ä¸ã minifyrb ã®å¦ç対象ã§ããããå¤ã Ruby ã§ä½¿ããããããªã¦ã¼ã¹ã±ã¼ã¹ãããã°ãã¦ã¼ã¹ã±ã¼ã¹æ¬¡ç¬¬ã§ãµãã¼ããèãã¦ã¿ã¾ãã®ã§ã声æããã ãã (ãã¡ããå¿ ããããå¿ãã§ãããã¯ãããã¾ãã) ã
æ¢ç¥ã®èª²é¡
ã¾ã ãã°ãããã¾ãã
ç°¡åãªããã°ã©ã ã§ããã° minify ã«ãã£ã¦å£ãããã¨ã¯ãã¾ããªãããããã¾ããããå¼±ç¹ã®ã²ã¨ã¤ã«ãã¢ããã¥ã¡ã³ããããã¾ã (ãããã¢ããã¥ã¡ã³ãã§ã) ã
ã¾ããç»å£å¾ã«ãºãããã«æãã¦ããã£ãp +a; p (1;2)
ã p+a;p(1;2)
ã®ã·ã³ã¿ãã¯ã¹ã¨ã©ã¼ã«ãªãåé¡ã¯ 0.1.0 æç¹ã§æªè§£æ±ºã§ã (ããã¯ãã) ã
ãã¸ãã¯ã³ã¡ã³ãã«ã¤ãã¦ã minifyrb ã«ãã£ã¦åé¤ãã¾ãããfrozen string literal ãã¸ã³ã¡ã¯ frozen ã解ãã ããªã®ã§å¤§ããªåé¡ã¯ãªãããã§ãããString#frozen?
ã®ãããªã¡ã½ããã使ã£ãå¦çåå²ãããã¨åé¡ãåºã¾ããã¾ãã¨ã³ã³ã¼ãã£ã³ã°ã«å¯¾ãããã¸ãã¯ã³ã¡ã³ãã UTF-8 以å¤ã®å ´åã¯ãã¹ã¯ãªããã¨ã³ã³ã¼ãã£ã³ã°ã®é¢ä¿ã§åé¡ãåºãå¯è½æ§ãããã¾ãããã®ãããã¯ãã¸ãã¯ã³ã¡ã³ããæ¶ããæ®ããããäºæãªãã·ã§ã³ãè¨ããããããã¨ãã©ã¡ããã«å²ãåããã¯ã¾ã 決ãã¦ããªã段éã§ãã
éçºè ãã¼ã
2019å¹´ã®å¹³æRubyä¼è°01åãã«å®è£ ãã RuboCop Faker 以æ¥ã4å¹´åã¶ããããã®æ°ä½ Gem ã§ãããã® RuboCop Faker ã¯ãã¾ã¯ã¾ããã® 10,000,000 ãã¦ã³ãã¼ãè¶ ããã¦ãã¦ããã¸ãã¨ããæ°æã¡ã
RuboCop Faker ã¯ç¾ä¸ã®çãç®çã«æ確ãªèª²é¡ã解ãããã«å®è£ ãããã®ã§ããããä»åã® Minify Ruby ã¯ç¾ä¸ã®çãç®çã«ãã¦ããªããã®ã§ãRuboCop ãªã¼ãã³ã¬ã¯ãã®ããããã³ã以å¤ã§ãã©ããªç¾å®ä¸çã®åé¡ã解ãã¦ã¼ã¹ã±ã¼ã¹ãèªçããã楽ãã¿ã§ãã
èªçããèæ¯ãè¨è¨çãªé¨åã¯ä»¥ä¸ã®ã¹ã©ã¤ãããåç §ãã ããã
ã¾ãé¢é£ããè¨äºã¨ãã¦ã大éªRubyä¼è°04ã§ã®è©±ã¯ä»¥ä¸ããåç §ãã ããã