Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Strip-block-comments/Ruby/strip-block-comments.rb
Normal file
32
Task/Strip-block-comments/Ruby/strip-block-comments.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
def remove_comments!(str, comment_start='/*', comment_end='*/')
|
||||
while start_idx = str.index(comment_start)
|
||||
end_idx = str.index(comment_end, start_idx + comment_start.length) + comment_end.length - 1
|
||||
str[start_idx .. end_idx] = ""
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def remove_comments(str, comment_start='/*', comment_end='*/')
|
||||
remove_comments!(str.dup, comment_start, comment_end)
|
||||
end
|
||||
|
||||
example = <<END_OF_STRING
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
END_OF_STRING
|
||||
|
||||
puts remove_comments example
|
||||
Loading…
Add table
Add a link
Reference in a new issue