Sam Thorpe wrote in post #1114567:
> I want to input a string of characters, and have it be read by every
> three characters so I can translate it per three characters.

Hi Sam, assuming you're talking about a command-line script that reads 
from the keyboard and acts after every third character, you'll have to 
get your ruby script to interact with the command-line environment (the 
console).  Usually consoles buffer all keyboard input, and only send it 
to an inner program when a particular trigger fires (usually the user 
hitting Enter).

In Windows, talking to the COMMAND console (command.com, cmd.exe, etc.) 
you'd usually have to use a library like conio, although I'm not sure if 
there are any ruby bindings for conio.

In a Unix-like environment, talking to a VT-type console or TTY, you 
have options.  The most common would be something like curses, which I 
think did have ruby bindings, and probably still does.

I've not used either from ruby, but it's hopefully a starting point.


However if you're actually just talking about breaking a string up into 
three-character chunks, you could do something like this:

    print "Type something: "
    s = gets.chomp
    s.scan(/.{1,3}/).each do |chunk|
      p chunk
    end

-- 
Posted via http://www.ruby-forum.com/.