# (0..4).step(obj with to\_int)

**URL:** <https://www.ruby-forum.com/t/0-4-step-obj-with-to-int/136371>\
**Category:** Development\
**Created:** [May 1, 2008, 10:18am UTC](https://www.ruby-forum.com/t/0-4-step-obj-with-to-int/136371 "2008-05-01T10:18:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [May 1, 2008, 10:18am UTC](https://www.ruby-forum.com/t/0-4-step-obj-with-to-int/136371/1 "2008-05-01T10:18:16Z")

</div>

e$B0J2\<$N$h$&$K!"e(Bstep e$B$N0z?t$Ke(B to\_int  
e$B$r$b$D@0?t$b$I$-$rM?$($ke(B  
e$B$HNc30$K$J$j$^$9!#e(B

% ./ruby -ve ‘o=Object.new; def o.to\_int() 1 end; (0…4).step(o) {|v| p  
v }’  
ruby 1.9.0 (2008-05-01 revision 16250) [i686-linux]  
0  
-e:1:in `+': Object can't be coerced into Fixnum (TypeError) from -e:1:in`step’  
from -e:1:in `’

1.8.6p111 e$B$G$O$J$j$^$;$s$G$7$?!#e(B

% ruby-1.8.6p111 -ve ‘o=Object.new; def o.to\_int() 1 end;  
(0…4).step(o) {|v| p v }’  
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]  
0  
1  
2  
3  
4
