String#ggsub

W

William James

James said:
#!/usr/local/bin/ruby -w

module Kernel
def complete
loop { break unless yield }
end
end

if __FILE__ == $0
digits = "3211"
complete { digits.gsub!(/(\d)\1+/) { |d| d[0, 1].to_i + 1 } }
p digits # => "4"
end

complete { digits.gsub!(/(\d)\1+/) { $1.to_i + 1 } }
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top