ruby 1.9: handling meta and control keys

Discussion in 'Ruby' started by (rkumar) Sentinel, Oct 4, 2009.

  1. 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/.
     
    (rkumar) Sentinel, Oct 4, 2009
    #1
    1. Advertising

  2. (rkumar) Sentinel, Oct 4, 2009
    #2
    1. Advertising

  3. (rkumar) Sentinel

    Ryan Davis Guest

    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/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.


    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"
     
    Ryan Davis, Oct 4, 2009
    #3
  4. 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/.
     
    (rkumar) Sentinel, Oct 4, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nym Pseudo

    META NAME and META HTTP-EQUIV

    Nym Pseudo, Sep 26, 2003, in forum: HTML
    Replies:
    1
    Views:
    563
    =?iso-8859-1?Q?brucie?=
    Sep 26, 2003
  2. Erik Jones
    Replies:
    8
    Views:
    312
    Andreas Kraemer
    Oct 11, 2007
  3. Duane Johnson

    Meta methods to govern meta data?

    Duane Johnson, Oct 25, 2005, in forum: Ruby
    Replies:
    6
    Views:
    245
    Adam Sanderson
    Oct 28, 2005
  4. Erik Veenstra

    Meta-Meta-Programming

    Erik Veenstra, Feb 7, 2006, in forum: Ruby
    Replies:
    29
    Views:
    395
    Erik Veenstra
    Feb 8, 2006
  5. Erik Veenstra

    Meta-Meta-Programming, revisited

    Erik Veenstra, Jul 21, 2006, in forum: Ruby
    Replies:
    21
    Views:
    444
    Erik Veenstra
    Jul 25, 2006
Loading...

Share This Page