... And here's a convenient helper

class Array
  def to_2d_a(ruby_type)
    sub_count = self.length
    max_sub_len = self.map{ |a| a.length }.max

    ar = System::Array.CreateInstance(ruby_type.to_clr_type, sub_count,
max_sub_len)

    self.each_with_index do |sub, idx|
      sub.each_with_index do |item, sub_idx|
        ar[idx, sub_idx] = item
      end
    end

    ar
  end

used like this

[[1,2],[3,4,5],[6,7]].to_2d_a(System::Int32)

:-)

On Mon, Nov 30, 2009 at 1:44 PM, Curt Hagenlocher <cu...@microsoft.com>wrote:
>
>>  You can create an array using the BCL by calling Array.CreateInstance.
>> >From C#, it would look like this:
>>
>>
>>
>> Array.CreateInstance(typeof(object), 5, 6)); // Equivalent to new
>> object[5,6]
>>
>>
>>
>> I don't have IronRuby on this machine and don't want to guess at the right
>> syntax.
>>
>>
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to