X.times dont work


#1

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


#2

You don’t have a block:
3.times { puts “dsds” }


#3

Dawid Skomski wrote:

    from (irb):27


3.times{ puts “Hello!”}


#4

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:


#5

Hi,

And how about this ?

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


Martins


#6

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 G. II


#7

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


#8

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: