def parallelize(data, num_slices=nil, serializer=nil)
      num_slices ||= default_parallelism
      serializer ||= default_serializer

      serializer.check_each(data)

      # Through file
      file = Tempfile.new('to_parallelize', temp_dir)
      serializer.dump_to_io(data, file)
      file.close # not unlink
      jrdd = RubyRDD.readRDDFromFile(jcontext, file.path, num_slices)

      Spark::RDD.new(jrdd, self, serializer)
    ensure
      file && file.unlink
    end
def parallelize(data, num_slices=nil, serializer=nil)
      num_slices ||= default_parallelism
      serializer ||= default_serializer

      serializer.check_each(data)

      # Through file
      file = Tempfile.new('to_parallelize', temp_dir)
      serializer.dump_to_io(data, file)
      file.close # not unlink
      jrdd = RubyRDD.readRDDFromFile(jcontext, file.path, num_slices)

      Spark::RDD.new(jrdd, self, serializer)
    ensure
      file && file.unlink
    end
Distribute a local Ruby collection to form an RDD
 Direct method can be slow so be careful, this method update data inplace

 == Parameters:
 data:: Range or Array
 num_slices:: number of slice
 serializer:: custom serializer (default: serializer based on configuration)

 == Examples:
   $sc.parallelize(["1", "2", "3"]).map(lambda{|x| x.to_i}).collect
   #=> [1, 2, 3]

   $sc.parallelize(1..3).map(:to_s).collect
   #=> ["1", "2", "3"]