Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interesting result of a newbie mistake

0 views
Skip to first unread message

VICTOR GOLDBERG

unread,
May 7, 2008, 7:07:15 AM5/7/08
to
Instead of writing
a = %w{ ant cat dog }
I wrote
a = %{ ant cat dog }
puts a[2] --> 110

I didn't find an explanation for this result in Dave Thomas' book
Anybody volunteers a response?

Thanks,
Víctor

Robert Klemme

unread,
May 7, 2008, 7:15:34 AM5/7/08
to
2008/5/7 VICTOR GOLDBERG <vmgol...@verizon.net>:

irb(main):001:0> a = %{ ant cat dog }
=> " ant cat dog "
irb(main):002:0> a.class
=> String
irb(main):003:0> a[2]
=> 110
irb(main):004:0> a[2].chr
=> "n"

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

kranthi reddy

unread,
May 7, 2008, 7:36:53 AM5/7/08
to
[Note: parts of this message were removed to make it a legal post.]

When you have somthing like

a = %{ ant cat dog }
=> " ant cat dog "
irb(main):002:0> a.class
=> String
irb(main):003:0> a[2]
=> 110
irb(main):004:0> a[2].chr
=> "n"

it displaying the ascii value of that character at that paticular place

cheers,
kranthi

On Wed, May 7, 2008 at 4:45 PM, Robert Klemme <short...@googlemail.com>
wrote:

0 new messages