From: Alex Date: 2009-06-25T03:25:42+09:00 Subject: Re: How do I get an integer from an array? --001485f80ef6f27aea046d1c3bca Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Wed, Jun 24, 2009 at 2:18 PM, Peter Bailey wrote: > Roger Pack wrote: > > Peter Bailey wrote: > >> Yes, if it do pages.to_s, I get [["78"]]. > > > > Looks like you want pages[0][0].to_i or what not then. > > =r > > Yup. That did it. Thank you very much, Roger. Now, I have to admit, I've > never, ever seen that double array counter notation. [0][0]. That's > totally weird to me. But, it works! > > Dir.chdir("N:/infoconpdf") > file = "ehs-X7917735.pdf" > pages = `pdfinfo #{file}` > pages = pages.scan(/^Pages:[ ]{2,99}([0-9]+)/) > pages = pages[0][0].to_i > 1.upto(pages) do |n| > puts n > end > > I got: > 1 > 2 > 3 > 4 > 5 > 6 > 7... > 78 > -- > Posted via http://www.ruby-forum.com/. > The double notation works just like chaining any other methods together, IE foo = bar.method.method The index method of the array class is a method just like any other, so you could just as well write it like: foo.[](0).[](0) which calls the `[]' method on the result of the previous call of the `[]' method, which is an array. foo[0] is just a shortcut ruby gives you for calling foo.[](0) Alex --001485f80ef6f27aea046d1c3bca--