identifying and removing comments in a seprate ruby file

R

Robhy B.

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
 
J

Jeremy Bopp

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?

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
 
A

Alex Stahl

[Note: parts of this message were removed to make it a legal post.]

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. | (e-mail address removed)
|
 
Z

zuerrong

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 }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top