X.times dont work

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

···

--
Posted via http://www.ruby-forum.com/.

You don't have a block:
3.times { puts "dsds" }

Dawid Skomski wrote:

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

--

3.times{ puts "Hello!"}

Hi,

And how about this ?

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

···

--
Martins

On 4/26/06, Dawid Skomski <dskomski@gmail.com> wrote:

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

--
Posted via http://www.ruby-forum.com/\.

13 wrote:

Hi,

And how about this ?

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

--
Martins

Im thankful you :slight_smile:

···

--
Posted via http://www.ruby-forum.com/\.

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

···

--
Posted via http://www.ruby-forum.com/.

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

James Edward Gray II

···

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

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 :slight_smile:

···

--
Posted via http://www.ruby-forum.com/\.