views:

63

answers:

1

Ruby Programming control and meta combinations used for?

?a                        # character code
?\n                       # code for a newline (0x0a)

?\C-a                     # control a = ?A & 0x9f = 0x01
?\M-a                     # meta sets bit 7
?\M-\C-a                  # meta and control a
?\C-?                     # delete character

I came across the term when reading into the Ruby Pickaxe book, I'm not sure what on earth meta or control does, I assume it does something similar to C's bitshifting operators (<< >>) but I'm not sure, so decided to confirm.

+2  A: 

They're only used for data in strings, they don't effect any of the actual Ruby code itself. Think of them as shorthand for un-printable characters like "\n" and "\e" are.

One case I can think of is if you were talking to a telnet-like terminal. In that case, sending "?\C-?" to the connection would be like pressing the delete key on your keyboard if you were directly connected to the terminal.

telnet_socket << "?\C-?" #Write delete character to socket

Unless you're dealing with terminal-like or really esoteric systems I doubt you'll ever use them.

Luke