Interesting result of a newbie mistake

  • Thread starter VICTOR GOLDBERG
  • Start date
V

VICTOR GOLDBERG

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
 
R

Robert Klemme

2008/5/7 VICTOR GOLDBERG said:
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?

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
 
K

kranthi reddy

[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

2008/5/7 VICTOR GOLDBERG said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top