Nathan Olberding wrote:
> I'm having a little trouble understanding something. Save the following 
> script in an empty directory and run it:
>
> Dir.new(".").to_a.each do |x|
>     puts "x=#{x}"
>     puts "x.class=#{x.class}"
>     puts "x[0]=#{x[0]}"
>     puts
> end
>
> You should get output that looks something like this:
>
> x=.
> x.class=String
> x[0]=46
>
> x=..
> x.class=String
> x[0]=46
>
> x=listdir.rb
> x.class=String
> x[0]=108
>
> I was expecting x[0] to be a one-character string.
>
> 1) Why isn't x[0] a one-character string?
> 2) How do I determine what the first character of such a string is? I'm 
> guessing this isn't the proper way, but I'd like to understand why it 
> doesn't work.
>
>   
1)
Please look at the String documentation:
http://ruby-doc.org/core/classes/String.html#M001843


If used with a Fixnum, [] returns the ASCII value of the character at 
that position.

2)
Try using

x[0,1] to get the first character.

-Justin