Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Strings Working With Strings

Harish Ramachandran
Harish Ramachandran
9,171 Points

Strings in Ruby

I'm learning about Strings in Ruby and I'm at the part where Jason talks about first_name[0] pulling the ASCII value of the first letter of his name. I've tried this with my name and a few other variables in irb in my Mac Terminal but it seems to only return the actual value.

Ex:

name = "Harish"
puts name[0]

In this case, name[0] returns H but according to the video, it should return 72. I know I'm working with a newer version of Ruby than the one in the video - could this have anything to do with this? If not, did I do something wrong?

Thanks!

3 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Harish,

I believe this is due to being on a newer version of Ruby. I'm running Ruby 2.0.0p451 and to accomplish this I used the .ord method like so.

   name = "Jason"
   name[0].ord

I hope this helps.

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

or install ruby 1.8.7 and then irb :)

$ rbenv install -l
$ rbenv install 1.8.7-p358