Imelody
(Imelody __)
1
In C/C++ language, can use "//" to comment,such as "//i++ "
I want use ruby to distinguish the comment lines and code lines.
but fail. : (
f.each do|line|
puts line
if line =~ /^////.*/
puts "The line contain //."
end
end
Error: Unexpected tSTRING_BEG
···
--
Posted via http://www.ruby-forum.com/.
if line =~ /^////.*/
if line =~ /^\/\//
if line =~ %r{^//}
(note that the .* does nothing in your original regexp, i.e. it can be
removed without changing the behaviour)
···
--
Posted via http://www.ruby-forum.com/\.
Robert_K1
(Robert K.)
3
For comment lines it's probably better to allow for some indentation:
if %r{^\s*//} =~ line
puts "This is a comment: #{line}"
end
Kind regards
robert
···
On Thu, Sep 16, 2010 at 4:22 PM, Brian Candler <b.candler@pobox.com> wrote:
if line =~ /^////.*/
if line =~ /^\/\//
if line =~ %r{^//}
(note that the .* does nothing in your original regexp, i.e. it can be
removed without changing the behaviour)
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Imelody
(Imelody __)
4
understand, thanks you very much!
···
--
Posted via http://www.ruby-forum.com/.