ruby ã® inject ã£ã¦æ
£ããªãã¨å°ãç解ãã¥ããããªã¼ã¨æã£ãã®ã§ã極åãããããã説æããã¦ã¿ããã¹ãã ãããããããããããªã説æ ãã¦ã1 ãã 10 ã¾ã§ã®åè¨ãæ±ãããããªâã³ã¼ãããã£ãå ´å sum = 0 (1..10).each {|i| sum = sum + i } p sum # => 55 inject ã使ã£ã¦ãã®ããâã«æ¸ãã¾ãã p (1..10).inject(0) {|sum, i| sum + i } each 㨠inject ã§ã©ã®ããã«æ¸ãå¤ãã£ã¦ãããå³ã§ç¤ºãã¨ãããªâæãã injectã®å¼æ° 0 ã¯ããããã¯ãã¼ã«ã«ãª sum å¤æ°ã®åæå¤ã«ãªã£ã¦ã¾ããã§ããããã¯ã®å®è¡çµæã®å¤ã sum ã«ä»£å
¥ããã¦ãï¼åç®ä»¥éã®ã«ã¼ããå®è¡ãã¾ããã«ã¼ããã¦ããéã®ãåå¤æ°ã¨ãããã¯ã®ä¸èº«ã¯ãããªâæãã sum i ãããã¯ã®ä¸èº«(sum
{{#tags}}- {{label}}
{{/tags}}