Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ruby 1.9: handling meta and control keys

Reply
Thread Tools

ruby 1.9: handling meta and control keys

 
 
(rkumar) Sentinel
Guest
Posts: n/a
 
      10-04-2009
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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
(rkumar) Sentinel
Guest
Posts: n/a
 
      10-04-2009
(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/arti...acter_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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      10-04-2009

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

> (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/arti...acter_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.


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"



 
Reply With Quote
 
(rkumar) Sentinel
Guest
Posts: n/a
 
      10-04-2009
Ryan Davis 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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: storing meta data on dictionary keys Erik Jones Python 8 10-11-2007 10:40 PM
Meta-Meta-Programming, revisited Erik Veenstra Ruby 21 07-25-2006 10:26 PM
Meta-Meta-Programming Erik Veenstra Ruby 29 02-08-2006 08:22 PM
Meta methods to govern meta data? Duane Johnson Ruby 6 10-28-2005 03:57 AM
META NAME and META HTTP-EQUIV Nym Pseudo HTML 1 09-26-2003 09:13 AM



Advertisments