Knight's Travails (#27)

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

···

James Edward Gray II [mailto:james@grayproductions.net] 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
#
#

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

···

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...