[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[newbie] What means 1_000_000

EdUarDo

4/5/2006 8:52:00 AM

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?
2 Answers

Pete

4/5/2006 8:57:00 AM

0

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)


> --- Ursprüngliche Nachricht ---
> Von: EdUarDo <eduardo.yanezNOSPAM@NOSPAMgmail.com>
> An: ruby-talk@ruby-lang.org (ruby-talk ML)
> Betreff: [newbie] What means 1_000_000
> Datum: Wed, 5 Apr 2006 17:53:47 +0900
>
> 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?
>


Lutz Horn

4/5/2006 8:58:00 AM

0

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