Java byte array to Ruby
<p>I have a Desktop application using java swing frames. I have to rewrite the application to either Ruby or python. However I understand java to certain extent - I need help rewriting certain piece of the code in java.</p>

<p>1.</p>

<pre><code>byte[] ModuleGuid = new byte[]{
        (byte)0xe1, (byte)0x9a, (byte)0x69, (byte)0x01,
        (byte)0xb8, (byte)0xc2, (byte)0x49, (byte)0x80,
        (byte)0x87, (byte)0x7e, (byte)0x11, (byte)0xd4,
        (byte)0xd8, (byte)0xf1, (byte)0xbe, (byte)0x79
};
</code></pre>

<p>2.</p>

<pre><code>JAVA_PvAPI_SensorInfoEx[] lptSensorInfo =
        new JAVA_PvAPI_SensorInfoEx[(int)PsConstant.JAVA_PvAPI_GET_SENSOR_INFO_MAX];
</code></pre>

<ol>
<li><p>There's no such thing as <code>byte</code> in Ruby. When you want to store a sequence of bytes, you store it in a string:</p>

<pre><code>module_guid = "\xE1\x9A\x69\x01...".force_encoding('ASCII-8BIT')
</code></pre>

<p>If you want to copy and paste from Java code, then use:</p>

<pre><code>module_guid = [0xe1, 0x9a, ...].pack('c*')
</code></pre>

<p>By the way, I didn't declare the variable as <code>ModuleGuid</code> because capitalized identifiers are for constants in Ruby, and I didn't see the <code>final</code> keyword in your Java code.</p></li>
<li><p>Arrays in Ruby are just arrays. They can store any kind of objects. There's no <code>int[]</code> or <code>String[]</code> or <code>Whatever[]</code> in Ruby. Ruby arrays don't have fixed sizes and can be expanded or shrink any time. Your second piece of Java code can be rewritten as:</p>

<pre><code>sensor_info = []
</code></pre>

<p>But, depending on your use-case, this statement itself may not be necessary because in Ruby you have sooooo many ways to obtain an array.</p></li>
</ol>

java python ruby