# Object#tap $B$N%5%s%W%k(B

**URL:** <https://www.ruby-forum.com/t/object-tap-b-n-5-s-w-k-b/135338>\
**Category:** Development\
**Created:** [April 21, 2008, 10:30am UTC](https://www.ruby-forum.com/t/object-tap-b-n-5-s-w-k-b/135338 "2008-04-21T10:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8edcca/32.png) [@okkez](https://www.ruby-forum.com/u/okkez)\
**Post date:** [April 21, 2008, 10:30am UTC](https://www.ruby-forum.com/t/object-tap-b-n-5-s-w-k-b/135338/1 "2008-04-21T10:30:55Z")

</div>

okkez e$B$G$9!#e(B

1.8 e$B$Ne(B HEAD e$B$Ge(B Object#tap e$B$N%5%s%W%k%3!\<%I$,e(B Syntax  
Error e$B$K$J$C$FF0$-$^$;$s!#e(B

% ruby-1.8.x -v sample\_tap.rb  
ruby 1.8.7 (2008-04-20 patchlevel 5000) [i686-linux]  
sample\_tap.rb:4: syntax error, unexpected ‘.’, expecting $end  
.to\_a .tap {|x| puts “array: #{x.inspect}”}  
^

% ruby-1.9.x -v sample\_tap.rb  
ruby 1.9.0 (2007-12-25 revision 0) [i686-linux]  
original: 1…10  
array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  
evens: [2, 4, 6, 8, 10]  
squares: [4, 16, 36, 64, 100]

trunk(r13777e$B$+$ie(B)  
e$B$G$O%a%=%C%I8F$S=P$7$N%I%C%H$,A0$KIU$$$F$$$F$bF0$/$h$&$K$J$C$?e(B  
e$B$H$$$&OC$re(B ruby-dev:32393  
e$B$G8+$?$N$G!"$3$N7o$,e(B1.8e$B$K%P%C%/%]!\<%H$5$l$J$$$N$J$ie(B  
object.c e$B$N3:EvItJ,$rD\>$7$F$\*$$$?J}$,$h$$$H;W$$$^$9!#e(B

# e$B%a%=%C%I8F$S=P$7$N%I%C%H$r8e$m$K0$9$@$1$G$9$,!#!#!#e(B

# Index: object.c

— object.c (revision 16122)  
+++ object.c (working copy)  
@@ -502,10 +502,10 @@

- The primary purpose of this method is to “tap into” a method chain,
- in order to perform operations on intermediate results within the  
chain.
- 

- 
  - 

```
(1..10) .tap {|x| puts "original: #{x.inspect}"}

```

- 
  - 

```
  .to_a .tap {|x| puts "array: #{x.inspect}"}

```

- 
  - 

```
  .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}

```

- 
  - 

```
  .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}

```

- 
  - 

```
(1..10) .tap {|x| puts "original: #{x.inspect}"}.

```

- 
  - 

```
   to_a .tap {|x| puts "array: #{x.inspect}"}.

```

- 
  - 

```
   select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}.

```

- 
  - 

```
   map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}

```

  - 

\*/

---

<div class="post-metadata">

**Author:** ![okkez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8edcca/32.png) [@okkez](https://www.ruby-forum.com/u/okkez)\
**Post date:** [April 21, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/object-tap-b-n-5-s-w-k-b/135338/2 "2008-04-21T13:25:38Z")

</div>

At Mon, 21 Apr 2008 17:30:26 +0900,  
okkez wrote:

> # original: 1…10
> 
> - 
> - 
> 
> ```
> (1..10) .tap {|x| puts "original: #{x.inspect}"}.
> 
> ```
> 
> - 
> - 
> 
> ```
> to_a .tap {|x| puts "array: #{x.inspect}"}.
> 
> ```
> 
> - 
> - 
> 
> ```
> select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}.
> 
> ```
> 
> - 
> - 
> 
> ```
> map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}
> 
> ```
> 
> - 
> 
> \*/

ã€€ã”æŒ‡æ‘˜ã‚ã‚ŠãŒã¨ã†ã”ã–ã„ã¾ã™ã€‚å¹³å‡¡ã«ã“ã†ç›´ã—ã¦ã„ã„ã‹ã‚‚ã€‚

```
(1..10).tap {
  |x| puts "original: #{x.inspect}"
}.to_a.tap {
  |x| puts "array: #{x.inspect}"
}.select {|x| x%2==0}.tap {
  |x| puts "evens: #{x.inspect}"
}.map {|x| x*x}.tap {
  |x| puts "squares: #{x.inspect}"
}
```

---

<div class="post-metadata">

**Author:** ![okkez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/8edcca/32.png) [@okkez](https://www.ruby-forum.com/u/okkez)\
**Post date:** [April 22, 2008, 8:14am UTC](https://www.ruby-forum.com/t/object-tap-b-n-5-s-w-k-b/135338/3 "2008-04-22T08:14:33Z")

</div>

okkez e$B$G$9!#e(B

e$BJV?.$"$j$,$H$&$4$6$$$^$9!#e(B

> ```
> (1..10).tap {
> |x| puts "original: #{x.inspect}"
> }.to_a.tap {
> |x| puts "array: #{x.inspect}"
> }.select {|x| x%2==0}.tap {
> |x| puts "evens: #{x.inspect}"
> }.map {|x| x*x}.tap {
> |x| puts "squares: #{x.inspect}"
> }
> 
> ```

e$BAGKQ$J46$8$G$h$$$H;W$$$^$9!#e(B  
e$B=$@5$h$m$7$/$\*4j$$$7$^$9!#e(B

08/04/21 e$B$Ke(B Akinori MUSHA[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
e$B$5$s$O=q$-$^$7$?e(B:
