Forum: Ruby What means 1_000_000

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.
EdUarDo (Guest)
on 2006-04-05 12:55
(Received via mailing list)
Hi all,
trying ri and reading documentation for Benchmark I've seen an example
that says:

Benchmark.measure {"a"*1_000_000}

What's that literall? I've tried to do it with 1000000 instead of
1_000_000 and
it works too.

And what means the expression "a"*1000000? What do that?
Peter E. (Guest)
on 2006-04-05 12:58
(Received via mailing list)
it's just for readability!

1_000 is similar to 1000

> puts "x" * 20
xxxxxxxxxxxxxxxxxxxx

it just duplicates a string multiple times (in this case 20)
Lutz H. (Guest)
on 2006-04-05 13:04
(Received via mailing list)
EdUarDo <removed_email_address@domain.invalid> writes:
> Benchmark.measure {"a"*1_000_000}
>
> What's that literall? I've tried to do it with 1000000 instead of
> 1_000_000 and it works too.

It *is* the same, only more friendly for human readers.

> And what means the expression "a"*1000000? What do that?

Why don't you just try it in irb?

irb(main):001:0> "a" * 10
=> "aaaaaaaaaa"

It's that simple :)

Regards
This topic is locked and can not be replied to.