# Smallest peeve ever!

**URL:** <https://www.ruby-forum.com/t/smallest-peeve-ever/118273>\
**Category:** Ruby\
**Created:** [October 25, 2007, 9:25am UTC](https://www.ruby-forum.com/t/smallest-peeve-ever/118273 "2007-10-25T09:25:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [October 25, 2007, 9:25am UTC](https://www.ruby-forum.com/t/smallest-peeve-ever/118273/1 "2007-10-25T09:25:28Z")

</div>

I’m sure there’s no chance of this ever changing but I’m disappointed  
that the integer method “step”:

start.step(end, step\_size)

```
...wasn't more like:

```

step\_size.step(start, end)

```
...I just like having the start and end points grouped together with 

```

the  
step size singled out.  
Who’s with me?

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [October 25, 2007, 10:24am UTC](https://www.ruby-forum.com/t/smallest-peeve-ever/118273/2 "2007-10-25T10:24:00Z")

</div>

From: Just Another Victim of the Ambient M.

# start.step(end, step\_size)

# …wasn’t more like:

# step\_size.step(start, end)

# …I just like having the start and end points grouped

# together with the

# step size singled out.

# Who’s with me?

i’m w you. ruby is with you (quite).

## irb(main):016:0\> system “qri range.step” ------------------------------------------------------------- Range#step rng.step(n=1) {| obj | block } =\> rng

```
 Iterates over rng, passing each nth element to the block. If the
 range contains numbers or strings, natural ordering is used.
 Otherwise step invokes succ to iterate through range elements.

```

irb(main):018:0\* (0…10).step(2) {|x| p x}  
0  
2  
4  
6  
8  
10  
=\> 0…10

obviously, by definition of range, it will not cater negative steps

irb(main):030:0\> (10…0).step(-2) {|x| p x}  
ArgumentError: step can’t be negative

☹

maybe, before i request a change in step, i might as well request a  
change in #succ/#next first, like succ receiving an optional argument,  
eg…

1.succ #=\> 2  
(-1).succ #=\> 0

1.succ(1) #=\> 2  
(-1).succ(1 #=\> 0

1.succ(2) #=\> 3  
(-1).succ(2) #=\> 1

1.succ(-1) #=\> 0  
(-1).succ(-1)#=\> -2

so then,

irb(main):030:0\> (10…0).step(-2) {|x| p x}  
10  
8  
6  
4  
2  
0

I believe facets already does the succ(-n) part, but does not handle  
step(-n) which is pretty lame to me, imnho.

kind regards -botp

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [October 25, 2007, 1:13pm UTC](https://www.ruby-forum.com/t/smallest-peeve-ever/118273/3 "2007-10-25T13:13:07Z")

</div>

On Oct 25, 10:25 am, “Just Another Victim of the Ambient M.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> step size singled out.  
> Who’s with me?

You can help yourself 🙂

class Numeric  
def mystep(from, to, &block)  
raise ArgumentError unless block\_given?  
from.step(to, self) { |x| yield x }  
end  
end

5.step(10, 2) { |i| puts i }  
2.mystep(5, 10) { |i| puts i }

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [October 25, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/smallest-peeve-ever/118273/4 "2007-10-25T13:17:12Z")

</div>

> > def mystep(from, to, &block)  
> > third parameter is not necessary, just

def mystep(from, to)
