Downward assignments ã¨ããåå㧠Ruby ã«ææ¡ãããæ©è½ (mame ããä»å¹´ããããã¨ããããã¾ã) ã
p(2 * 3 * 7) #=> 42 ^^^^^var p var #=> 6
ã¨ã¤ããªã«ãã¼ã«ã¨ãããã¨ã失念ãã¦ãã¦ãããã¯ï¼ãã¨ãããããæã£ãä¸æ¹ã§æã£ãã®ãã以ä¸ã®ãã㪠RuboCop ã®ãã¹ãæ©æ§ã¨ã¶ã¤ãã£ãå ´åã«ããã¹ãã®ä»çµã¿ãèããå¿ è¦ããããããããªãã¨ããç¹ã ã£ã (ããã°ãã¾ããã) ã
expect_offense(<<~RUBY) def func some_preceding_statements x = something ^^^^^^^^^^^^^ Redundant assignment before returning detected. x end RUBY
ã¾ãä»ã®æ©è½ææ¡ã¨ãã¦ãmrkn ããããã¯ãããªææ¡ãéããã¦ãã¾ããã
irb(main):001:0> x = 3 => 3 irb(main):002:0> 2x => 6 irb(main):003:0> def pi = Math::PI => :pi irb(main):004:0> 2pi => 6.283185307179586
ã¨ã¤ããªã«ãã¼ã«ãã¿ã§ããã¨ãRuby 3.0 ã§æ£å¼æ¡ç¨ããã Endless Method Definition ã®ä¾ãããã®ã§ãæ°ã«ãªã人ã¯ã¦ã©ãããã¦ã¿ã¾ãããã
2021å¹´4æ5æ¥è¿½è¨
ãããã®ææ¡ãã¨ã¤ããªã«ãã¼ã«çµäºã¨ãããã¨ã§ã¯ãã¼ãºãããããã§ãã
[Feature #17768: Proposal: Downward assignments - Ruby master - Ruby Issue Tracking System](https://t.co/rQuRKFV2Fj) rejected :(
— _ko1 (@_ko1) 2021å¹´4æ5æ¥