From: Aldric Giacomoni Date: 2009-11-19T23:31:51+09:00 Subject: Re: How to strip ruby comments in a ruby line of code? Alexandre Mutel wrote: > Short description : My question is : do you know any available method, > giving the string of a Ruby line of code, to remove comments from this > line of code? > > I would like to have something really simple and not being forced to use > a full ruby language parser to parse those lines and remove the > comments. > > Any idea? > > Thanks! I'm still only learning regular expressions (I'll do another shameless plug for rubular.com here), but you could do this: string = string.match(/^.*#).to_s[0...-1] Yes, it's a poor solution, but should you have nothing else, it'll do. -- Posted via http://www.ruby-forum.com/.