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.
72eab3da25ac9aa625c314ba935f58f1?d=identicon&s=25 EdUarDo (Guest)
on 2006-04-05 10: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?
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-04-05 10: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)
3f9aa24fedd4991b512755a5d3a8ffad?d=identicon&s=25 Lutz Horn (Guest)
on 2006-04-05 11:04
(Received via mailing list)
EdUarDo <eduardo.yanezNOSPAM@NOSPAMgmail.com> 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.