Request for times, step, upto

Hi,

1. I am a Integer#times fan :slight_smile: So you see my (and my kids) nuby codes
littered w it. I have a small request though.
Can we pass initial and step params?

ie

from int.times {|i| block }

to int.times(starting=0, step=1) {|i| block }

I hope this would not break old code, right?

2. my request may be handled by step. But I do not like step (me only);
maybe because the sound does not ring or maybe because I do not like the
order of params when read.

iow

from num.step(limit, step ) {|i| block },

I prefer fr_num.step(step, upto ) {|i| block }

since I would read the ff 1.step(2,5) {|x| p x} as
"from 1 step 2 up to 5" (I know this would break old code)

I feel Integer#upto has a better read -"int.upto(limit) {|i| block }", but
sadly #upto has no steps either :frowning:

thanks for reading =)

kind regards -botp

Whether these make it into Ruby core or not (I'm all for it) I will definitely
add these mods too Ruby Facets (unless of course someone can show that its a
really bad idea, but I doubt that). Do you have them coded up already by
chance?

Thanks,
T.

路路路

On Friday 14 January 2005 02:06 am, "Pe帽a, Botp" wrote:

Hi,

1. I am a Integer#times fan :slight_smile: So you see my (and my kids) nuby codes
littered w it. I have a small request though.
Can we pass initial and step params?

ie

from int.times {|i| block }

to int.times(starting=0, step=1) {|i| block }

I hope this would not break old code, right?

2. my request may be handled by step. But I do not like step (me only);
maybe because the sound does not ring or maybe because I do not like the
order of params when read.

iow

from num.step(limit, step ) {|i| block },

I prefer fr_num.step(step, upto ) {|i| block }

since I would read the ff 1.step(2,5) {|x| p x} as
"from 1 step 2 up to 5" (I know this would break old code)

I feel Integer#upto has a better read -"int.upto(limit) {|i| block }", but
sadly #upto has no steps either :frowning:

thanks for reading =)

kind regards -botp

"Pe帽a, Botp" <botp@delmonte-phil.com> schrieb im Newsbeitrag
news:20050114070636.2F2EB83F5@mx2.delmonte-phil.com...

Hi,

1. I am a Integer#times fan :slight_smile: So you see my (and my kids) nuby codes
littered w it. I have a small request though.
Can we pass initial and step params?

ie

from int.times {|i| block }

to int.times(starting=0, step=1) {|i| block }

I hope this would not break old code, right?

Sure, but semantics of this method will be broken. The block will no
longer execute int times. We have #step for that as know.

2. my request may be handled by step. But I do not like step (me only);
maybe because the sound does not ring or maybe because I do not like the
order of params when read.

Ah, so you *do* care about the correlation between semantics and method
names.

iow

from num.step(limit, step ) {|i| block },

I prefer fr_num.step(step, upto ) {|i| block }

since I would read the ff 1.step(2,5) {|x| p x} as
"from 1 step 2 up to 5" (I know this would break old code)

I feel Integer#upto has a better read -"int.upto(limit) {|i| block }",

but

sadly #upto has no steps either :frowning:

That could be added. And it would be a resonable and good change IMHO.
Same for #downto btw.

thanks for reading =)

Thanks for calling. :slight_smile:

Kind regards

    robert

Hi,

I agree that Integer#step looks a bit odd. The most
natural way to do this is IMO with Range#step (added
in 1.8? ):

irb(main):001:0> (2..9).step(2) do |i| puts i end
2
4
6
8

KB

路路路

On Fri, 14 Jan 2005 16:06:19 +0900, Pe帽a, Botp wrote:

<snip>
2. my request may be handled by step. But I do not like step (me only);
maybe because the sound does not ring or maybe because I do not like the
order of params when read.

Robert Klemme schrieb:

"Pe帽a, Botp" <botp@delmonte-phil.com> schrieb im Newsbeitrag
news:20050114070636.2F2EB83F5@mx2.delmonte-phil.com...

>>

(...)

>>

int.times(starting=0, step=1) {|i| block }

I hope this would not break old code, right?

Sure, but semantics of this method will be broken. The block will no
longer execute int times. We have #step for that as know.

I thought he just wanted to change the values passed into the block. Instead of

   0, 1, ..., n-1

it would be

   start, start + step, ..., start + (n-1)*step

Looks useful to me.

Regards,
Pit