Mutterings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/usr/bin/ruby
def wipe_mutterings_from( sentence )
unless sentence.respond_to? :include?
raise ArgumentError,
"canot wipe mutterings from a #{ sentence.class }"
end
while sentence.include? '(' and sentence.include? ')'
# open = sentence.index( '(' )
# close = sentence.index( ')' , open)
# sentence[open..close] = '' if close
sentence.gsub!(/\s*\([^\(]*\)/, '')
end
end
foo = "This is a sentence (with some mutterings)."
wipe_mutterings_from( foo )
p foo
|