Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.


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?


3 Answers

Justin Horner
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"

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