From: Ted Flethuseo Date: 2011-01-28T11:52:03+09:00 Subject: Re: why is overloading invalid in ruby. 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=nil > if b.nil? > -a > else > a+b > end > end > > But I don't really know what you were asking. > I agree with Jesús. 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. class CSVFile attr_accessor :inFile attr_accessor :file_data attr_accessor :in_data attr_accessor :out_data attr_reader :count def initialize(file) @inFile = file @file_data = [] @count = 0 @in_data = [] @out_data = [] end def read_data if inFile.nil? == false @count = 0 File.foreach(inFile) do |line| arr = line.chomp.split(',') float_array = arr.map { |x| x.to_f } file_data.push(float_array) @count = @count + 1 end end return file_data end def read_data(num_in, num_out) if inFile.nil? == false @count = 0 File.foreach(inFile) do |line| arr = line.chomp.split(',') float_array = arr.map { |x| x.to_f } arr_in = [] arr_out = [] for i in 0...num_in arr_in << float_array[i] end in_data.push(arr_in) for j in num_in...(num_in+num_out) arr_out << float_array[j] end out_data.push(arr_out) @count = @count + 1 end end return file_data end def read_data(num_in, num_out, num_lines) if inFile.nil? == false @count = 0 File.foreach(inFile) do |line| if @count >= num_lines break; end arr = line.chomp.split(',') float_array = arr.map { |x| x.to_f } arr_in = [] arr_out = [] for i in 0...num_in arr_in << float_array[i] end in_data.push(arr_in) for j in num_in...(num_in+num_out) arr_out << float_array[j] end out_data.push(arr_out) @count = @count + 1 end end return file_data end end -- Posted via http://www.ruby-forum.com/.