Ruby 1.9ã§å°å ¥ãããObject#tapã¯Ruby 1.8ã§ã1.8.7ãã使ããããã«ãªã£ãã tapã¡ã½ããã¨ã¯ä½ãã¨ããã¨ãèªåèªèº«ã«ãããã¯ãä½ç¨ããã¦èªåèªèº«ãè¿ãã ãã®ã¡ã½ããã ãã¤ã¾ãå¯ä½ç¨å°éã¡ã½ãããå®ç¾©ã¯ããã£ã¦ç°¡åãã³ã¬ã class Object def tap yield(self) self end end ãã¨ãã°ã1ã4ã®äºä¹ã®ãã¡10以ä¸ã®ãã®ãæ±ããããã ãã©ããããã°æã¨ãã§éä¸çµéã§ãã1ã4ã®äºä¹ã表示ãã¦ã»ãããªãã¦å ´åã¯ãããªæãã«ããããªããªã£ããtapã®é¨åãæ¶ãã°ããã楽ãã³ã ary = [1, 2, 3, 4] ary.map{|x| x**2}.tap{|a| p a}.select {|x| x>10 } # => [16] # >> [1, 4, 9, 16] ã»ãã«ããç ´å£çã¡ã½ãããé©ç¨ããå¾ã§èªåèªèº«ãè¿ãå ´åã«ã
{{#tags}}- {{label}}
{{/tags}}