[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Interesting result of a newbie mistake

VICTOR GOLDBERG

5/7/2008 11:07:00 AM

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

2 Answers

Robert Klemme

5/7/2008 11:16:00 AM

0

2008/5/7 VICTOR GOLDBERG <vmgoldberg@verizon.net>:
> 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

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

kranthi reddy

5/7/2008 11:37:00 AM

0

[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 <shortcutter@googlemail.com>
wrote:

> 2008/5/7 VICTOR GOLDBERG <vmgoldberg@verizon.net>:
> > 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
>
> --
> use.inject do |as, often| as.you_can - without end
>
>