# Ruby 1.9: handling meta and control keys

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658>\
**Category:** Ruby\
**Created:** [October 4, 2009, 9:07am UTC](https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658 "2009-10-04T09:07:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 4, 2009, 9:07am UTC](https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658/1 "2009-10-04T09:07:55Z")

</div>

1.8 used to return an int for say ?\M-a or ?C-a (when user types meta-a  
or control-a).

1.9 returns a string as “\xE1” instead of 225.

The only way i have been able to convert “\xE1” to 225 is removing the  
first 2 chars and then using to\_i(16).

“E1”.to\_i(16)

If i do:

“\xE1”.to\_i(16) i get a zero.

Is there a clean way of handling meta and control chars in 1.9. Or at  
least a clean way of converting them to integers. I need them as  
integers since I am porting a 1.8 app that uses them as integers.

Also, is there anyone using the return values of ?\M-a etc as is,  
without conversion. I would like to hear how.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 4, 2009, 9:28am UTC](https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658/2 "2009-10-04T09:28:13Z")

</div>

(rkumar) Sentinel wrote:

> 1.8 used to return an int for say ?\M-a or ?C-a (when user types meta-a  
> or control-a).
> 
> 1.9 returns a string as “\xE1” instead of 225.

After further searching on :  
[http://blog.grayproductions.net/articles/what\_is\_a\_character\_encoding](http://blog.grayproductions.net/articles/what_is_a_character_encoding)

I found this:

```
?\M-a.getbyte(0)

```

It works, however any suggestions on how i can write this so it works  
for both 1.8 and 1.9 would be welcome.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 4, 2009, 10:17am UTC](https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658/3 "2009-10-04T10:17:46Z")

</div>

On Oct 4, 2009, at 00:28 , (rkumar) Sentinel wrote:

> I found this:
> 
> ?\M-a.getbyte(0)
> 
> It works, however any suggestions on how i can write this so it works  
> for both 1.8 and 1.9 would be welcome.

This is what I use in ruby\_parser:

# I hate ruby 1.9 string changes

class Fixnum  
def ord  
self  
end  
end unless “a”[0] == “a”

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 4, 2009, 10:46am UTC](https://www.ruby-forum.com/t/ruby-1-9-handling-meta-and-control-keys/176658/4 "2009-10-04T10:46:19Z")

</div>

Ryan D. wrote:

> class Fixnum  
> def ord  
> self  
> end  
> end unless “a”[0] == “a”

Thanks for the instant reply. I’ve followed the same with getbyte.  
– rk
