user4263: I'm trying to send data over serial and pick it up in a ruby script. I'm using the serialport gem (https://rubygems.org/gems/serialport) as stated in the Arduino docs (http://playground.arduino.cc/Interfacing/Ruby). 
My question is, I'm trying to print out some gyroscope data, particularly the x, y, and z. This is what my arduino sketch looks like:
void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.print((int)gyro.g.z);

  delay(500);
}

My ruby script is pretty straight forward as well:
require "serialport"
port_str = "/dev/tty.usbmodemfa141"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
while true do
  message = sp.gets
  if message
    message.chomp!

    puts message
  end
end

However, the output that I get is choppy. What I mean by that is that the numbers don't come out as a single line as I intend:
52 9
5
250
 -28
 85
25
9 -5
1 69

Even if I replace it with "Hello World", it'll come out as:
He
llo
Wor
ld

or similar.
Any ideas why? Thanks in advance for any help.

user4568: Firstly, let's look into documentation for Ruby IO#gets:

Reads the next "line" from the I/O stream; lines are separated by sep ...

Secondly, look into documentation for Arduino Serial.print:

Prints data to the serial port as human-readable ASCII text ...

Finally, you don't print new line char \n in your "arduino sketch" above.
I recommend you to use Serial.println in the last line from your sketch:
void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.println((int)gyro.g.z);

  delay(500);
}


4263: <p>I'm trying to send data over serial and pick it up in a ruby script. I'm using the serialport gem (<a href="https://rubygems.org/gems/serialport" rel="nofollow">https://rubygems.org/gems/serialport</a>) as stated in the Arduino docs (<a href="http://playground.arduino.cc/Interfacing/Ruby" rel="nofollow">http://playground.arduino.cc/Interfacing/Ruby</a>). </p>

<p>My question is, I'm trying to print out some gyroscope data, particularly the x, y, and z. This is what my arduino sketch looks like:</p>

<pre><code>void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.print((int)gyro.g.z);

  delay(500);
}
</code></pre>

<p>My ruby script is pretty straight forward as well:</p>

<pre><code>require "serialport"
port_str = "/dev/tty.usbmodemfa141"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
while true do
  message = sp.gets
  if message
    message.chomp!

    puts message
  end
end
</code></pre>

<p>However, the output that I get is choppy. What I mean by that is that the numbers don't come out as a single line as I intend:</p>

<pre><code>52 9
5
250
 -28
 85
25
9 -5
1 69
</code></pre>

<p>Even if I replace it with "Hello World", it'll come out as:</p>

<pre><code>He
llo
Wor
ld
</code></pre>

<p>or similar.</p>

<p>Any ideas why? Thanks in advance for any help.</p>
 4568: <p>Firstly, let's look into documentation for <a href="http://www.rubydoc.info/stdlib/core/IO:gets" rel="nofollow">Ruby IO#gets</a>:</p>

<blockquote>
  <p>Reads the next "line" from the I/O stream; lines are separated by sep ...</p>
</blockquote>

<p>Secondly, look into documentation for <a href="http://arduino.cc/en/Serial/Print" rel="nofollow">Arduino Serial.print</a>:</p>

<blockquote>
  <p>Prints data to the serial port as human-readable ASCII text ...</p>
</blockquote>

<p>Finally, you don't print new line char <code>\n</code> in your "arduino sketch" above.</p>

<p>I recommend you to use <code>Serial.println</code> in the last line from your sketch:</p>

<pre><code>void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.println((int)gyro.g.z);

  delay(500);
}
</code></pre>
