From: John W Higgins Date: 2011-01-28T13:43:50+09:00 Subject: Re: why is overloading invalid in ruby. --0016364ef40a43c038049ae0b6fe Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Good Evening, On Thu, Jan 27, 2011 at 6:52 PM, Ted Flethuseo 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 > > if b.nil? > > -a > > else > > a+b > > 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. > > How about this - I'm unsure of some of the variables - they seem a little strange but I'm sure you can debug any issues in that respect - I just used pretty much what you provided. def read_data(num_in =3D nil, num_out =3D nil, num_lines =3D nil) #This just looks a little nicer than the if .nil? =3D=3D false unless @inFile.nil? #Either we are provided the number of lines to use or we use them all num_lines ||=3D @inFile.length #Instead of counting where we are we just limit our group to what we want myFiles =3D @inFile[0...num_lines] #Use our limited dataset File.foreach(myFiles) do |line| arr =3D line.chomp.split(',') float_array =3D arr.map { |x| x.to_f } #Make a choice based on the num_in variable if num_in.nil? @file_data.push(float_array) else #Much simpler here - no need for the loops and temp vars #Just grab what we need and move along in_data << float_array[0...num_in] out_data << float_array[num_in...(num_in+num_out)] end end end return @file_data end --0016364ef40a43c038049ae0b6fe--