Forum: Ruby x.times dont work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4125fb46736d33620ec01f18f8c96d73?d=identicon&s=25 Dawid Skomski (eneon)
on 2006-04-26 09:34
Hi

In irb i wrote 3.time(puts "dsds") and it doesn't work why?
Here i pasted log:

irb(main):027:0> 3.times(puts "Hello!")
(irb):27: warning: parenthesize argument(s) for future version
Hello!
ArgumentError: wrong number of arguments (1 for 0)
        from (irb):27:in `times'
        from (irb):27
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-04-26 09:46
(Received via mailing list)
You don't have a block:
3.times { puts "dsds" }
Bf65925bf8c591faa60e13ac1962b2e8?d=identicon&s=25 Huajian.Luo (Guest)
on 2006-04-26 09:46
(Received via mailing list)
Dawid Skomski wrote:
>         from (irb):27
>
> --
3.times{ puts "Hello!"}
Be13d49ea40add75e564bef96b323caf?d=identicon&s=25 13 (Guest)
on 2006-04-26 09:46
(Received via mailing list)
Hi,

And how about this ?

irb(main):005:0> 3.times { puts("Hello!") }
Hello!
Hello!
Hello!
=> 3

--
Martins
4125fb46736d33620ec01f18f8c96d73?d=identicon&s=25 Dawid Skomski (eneon)
on 2006-04-26 11:48
13 wrote:
> Hi,
>
> And how about this ?
>
> irb(main):005:0> 3.times { puts("Hello!") }
> Hello!
> Hello!
> Hello!
> => 3
>
> --
> Martins

Im thankful you :)
3324a49b1605f0e2df7676ff64f5e712?d=identicon&s=25 Mohammad Ruby (mohammad)
on 2006-04-26 19:48
isn't easier just to wright
number.times do
puts "whatever"
end
i find this alot better then blocking it
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-26 19:58
(Received via mailing list)
On Apr 26, 2006, at 12:48 PM, Mohammad wrote:

> isn't easier just to wright
> number.times do
> puts "whatever"
> end
> i find this alot better then blocking it

do ... end is also a block.  Just another way to write it.

James Edward Gray II
4125fb46736d33620ec01f18f8c96d73?d=identicon&s=25 Dawid Skomski (eneon)
on 2006-04-27 08:13
Mohammad  wrote:
> isn't easier just to wright
> number.times do
> puts "whatever"
> end
> i find this alot better then blocking it

Yes, i like do..end more than {} blocks, too :)
This topic is locked and can not be replied to.