From: Arun Kumar Date: 2009-03-26T21:52:03+09:00 Subject: Re: passing parameter Robert Klemme wrote: > 2009/3/26 Arun Kumar : >> Hi, >> This is my code strip >> >> �contents.each do |content| >> � � � � � � � � � �#scanning the content using regexp to fetch the url >> � � � � � � � � � �url = content.scan(/(http:\/\/.*|https:\/\/.*)/i) > > Two notes: #scan returns a potentially empty Array and not a single > object. > > And you can make the regexp simpler and more efficient at the same time > > /https?:\/\/.*)/i > > Note also that using ".*" is dangerous because depending on your input > this may match too much. > >> � � � � � � � � � �data = Net::HTTP.get(URI.parse("#{url}")) > > The construct "#{expr}" is better replaced by expr.to_s and in this > case, since url should be String you do not even need that. > >> � � � � � � � � � �#extracting the feeds url from 'data' using 'regexp' >> � � � � � � � � � �xml = data.scan(/> rel="alternate".*?href="(.*?xml|.*?rdf)"/i) >> � � � � � � � �end >> >> Now what i want is to pass the 'xml' variable as a parameter to the next >> class but i'm not able to do that because the 'xml' variable is inside >> an array. Can anybody please tell me about how to do it. > > Where is "xml in an array"? The variable "xml" references an Array > because you use String#scan (see above). You can simply iterate that > Array as any other Array, too. Where is the problem? Hi, The problem is that i need to parse the xml from the feeds url and the code for it is written in another class. So I need to pass the feed url ie.'xml'. Since it is written inside an iterator ie. in between each do|content|, i cannot pass it as a prameter to the other class since xml variable will not be accessible after the iterator ends. Please help me. N. B. Writing the code will be more helpfull for me to understand Regards Arun Kumar -- Posted via http://www.ruby-forum.com/.