From: H- 16 Date: 2010-04-11T05:54:51+09:00 Subject: Re: global variable in ruby Amishera Amishera wrote: > Trying to use some global variable > > $buffer = Array.new > 4 > 5 def save_log(data, file_name) > 6 puts 'save log called '+file_name > 7 open(file_name, 'w') { |f| f.write(data) } > 8 end > 9 > 10 def get_citations_from_page(data, start_point, end_point) > 11 citations = get_substring_within_inclusive(data, > start_point, end_point) > 12 u_arr = getURLsFromPage('http://www.xxxx.com/', citations) > 13 u_arr.each { > 14 |t| > 15 if >> (!beginsWith(t[1],'http://www.xxxx.com//gp/reader')) >> 16 buffer.push t[0]+'%%%'+t[1] > 17 end > 18 } > 19 end The reason this is happening is because you forgot to write $ in buffer.push. It should be $buffer.push. But you could just put a buffer var to get passed into the function. >10 def get_citations_from_page(data, start_point, end_point, buffer) and then just write buffer for the last argument. -- Posted via http://www.ruby-forum.com/.