Identifying and removing comments in a seprate ruby file

Hi everyone,

I'm working on a ruby program that's supposed to find and remove single
line comments starting with "#" and block comments starting with
"=begin" and finishing with "=end" from a separate ruby source file. I'm
having trouble with this assignment can anyone help?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

If you're asking for help with homework, you'll probably get some help
if you show some of what you've done so far and/or what exactly you're
having trouble doing. For instance, are you having problems opening the
file, reading its contents, or identifying the contents of interest once
you read them? Is your program raising errors? If so, what errors?

-Jeremy

···

On 12/08/2010 07:31 PM, Robhy B. wrote:

Hi everyone,

I'm working on a ruby program that's supposed to find and remove single
line comments starting with "#" and block comments starting with
"=begin" and finishing with "=end" from a separate ruby source file. I'm
having trouble with this assignment can anyone help?

Allow me...

To answer your question, yes, there's lots of people that can help.

But no one likes doing homework for others. You'll get better results
if you show some effort to solve the problem and have a specific
question about some implementation detail.

···

________________________________________________________________________

Alex Stahl | Sr. Quality Engineer | hi5 Networks, Inc. | astahl@hi5.com

On Wed, 2010-12-08 at 19:31 -0600, Robhy B. wrote:

Hi everyone,

I'm working on a ruby program that's supposed to find and remove single
line comments starting with "#" and block comments starting with
"=begin" and finishing with "=end" from a separate ruby source file. I'm
having trouble with this assignment can anyone help?

Thanks

I wrote a simple one, maybe that's not so good.

$ cat 1.rb
# this is a comment

arr = [1,2,3,4]

# now loop through the array

arr.each {|s| puts s }

=begin
  author: somebody else
  date: 2010-12-12
=end

$ cat rmcomm.rb
lab=0
File.open("1.rb").each_line do |s|
   next if s=~/^#|^$/
   if s=~/^=begin/
      lab = 1
   elsif s=~/^=end/
      lab = 0
      next
   end
   next if lab == 1
   puts s
end

$ ruby rmcomm.rb
arr = [1,2,3,4]
arr.each {|s| puts s }

···

2010/12/9 Robhy B. <robhy05@hotmail.com>:

Hi everyone,

I'm working on a ruby program that's supposed to find and remove single
line comments starting with "#" and block comments starting with
"=begin" and finishing with "=end" from a separate ruby source file. I'm
having trouble with this assignment can anyone help?

Thanks

--
Posted via http://www.ruby-forum.com/\.