[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Knight's Travails (#27

Peña, Botp

4/16/2005 1:51:00 AM

James Edward Gray II [mailto:james@grayproductions.net] wrote:
#On Apr 15, 2005, at 7:50 PM, Peña, Botp wrote:
#
#> #> btw, is there a Char class?
#> #
#> #No, there's not. See Integer#chr.
#>
#> i was looking for the other way around, like Chr#integer.
#
#We've just been playing with examples of that:
#
#String#[char_index]

yes; but it still is other way around; so one has to take one more step.

irb(main):016:0> x="string"[0]
=> 115

irb(main):021:0> x.chr
=> "s"

# or

irb(main):022:0> x="string"[0].chr
=> "s"



i was hoping to get

irb(main):016:0> x="string"[0]
=> "s"

thinking that a string is a sequence of chars. i do not want to think char
as int (or long :); it feels like asm/hardcoreC prgg...

it is really a nuby thingy question. may not be important really...

thanks and kind regards -botp

#
#James Edward Gray II
#
#



1 Answer

James Gray

4/16/2005 1:56:00 AM

0

On Apr 15, 2005, at 8:50 PM, Peña, Botp wrote:

>
> irb(main):016:0> x="string"[0]
> => 115
>
> irb(main):021:0> x.chr
> => "s"
>
> # or
>
> irb(main):022:0> x="string"[0].chr
> => "s"
>
>
>
> i was hoping to get
>
> irb(main):016:0> x="string"[0]
> => "s"
>
> thinking that a string is a sequence of chars. i do not want to think
> char
> as int (or long :); it feels like asm/hardcoreC prgg...

irb(main):001:0> "string"[0, 1]
=> "s"

I believe it's planned to have "string"[0] return "s" in Ruby 2, as
well.

James Edward Gray II