On Thu, Jan 27, 2011 at 9:52 PM, Ted Flethuseo <flethuseo / gmail.com> wrote:
> David Masover wrote in post #978005:
>> On Thursday, January 27, 2011 02:55:24 pm Ted Flethuseo wrote:
>>> Ah that's too bad... I knew I could put some default values for x and y
>>> and z.. getting the same effect sort of...
>>>
>>> but this isn't a solution if the methods that I want to "overload" (I
>>> call it
>>> overload, not sure what the proper term should be) are
>>> completely different, and are not differentiated simply by different
>>> values.
>>
>> If they're not differentiated by different values, how were you
>> expecting
>> overloading to work? If the problem is that you need the behavior to be
>> different, I think default values still work -- for example:
>>
>> def sum_or_inverse a, b=3Dnil
>> =A0 if b.nil?
>> =A0 =A0 -a
>> =A0 else
>> =A0 =A0 a+b
>> =A0 end
>> end
>>
>> But I don't really know what you were asking.
>> I agree with Jes=FAs. We need more details.
>
> Ok.. I didn't want to post so much code but you asked for it. I am
> trying to read a file, with a number of different methods. The methods
> allow you to interpret the file as an input and output matrices, input
> only or both but with only a number of rows.

Infinity =3D 1.0/0

def read_data(num_in =3D nil, num_out =3D nil, num_lines =3D Infinity)
=A0=A0unless inFile.nil?
=A0=A0 =A0@count =3D 0

=A0=A0 =A0File.foreach(inFile) do |line|
      # def read_data(num_in, num_out, num_lines)
=A0  =A0 =A0break if @count >=3D num_lines

=A0    =A0arr =3D line.chomp.split(',')
=A0 =A0=A0  float_array =3D arr.map { |x| x.to_f }

      # def read_data(num_in, num_out)
      if num_in and num_out
  =A0  =A0 =A0arr_in =3D []
=A0   =A0=A0 =A0arr_out =3D []
=A0 =A0    =A0for i in 0...num_in
=A0 =A0 =A0  =A0 =A0arr_in << float_array[i]
=A0 =A0 =A0 =A0 end

 =A0 =A0 =A0 =A0in_data.push(arr_in)
=A0  =A0 =A0 =A0for j in num_in...(num_in+num_out)
=A0    =A0 =A0 =A0arr_out << float_array[j]
=A0 =A0=A0   =A0end
  =A0  =A0 =A0out_data.push(arr_out)
      elsif num_in or num_out
        raise ArgumentError
      else
        # def read_data
        file_data.push(float_array)
=A0     end

=A0   =A0=A0@count =3D @count + 1
=A0 =A0 end

=A0 =A0 file_data
  end
end