D
Deniz Dogan
Hello.
I'm trying to come up with the "best", most Ruby-ish way to write a
method such as this one:
# This method replaces randomly selected characters in 'string' with new
# randomly selected characters of [A-Za-z0-9]. However, it does not
# replace any character with the character itself, i.e., it does not
# replace any "a" with "a". Also, no position in the string will ever be
# replaced twice.
# 'string' is the String to perform the replacing on.
# 'amount' is the amount of different characters to replace.
def random_replace(string, amount)
...
end
You don't have to care about any error checking of course.
Any ideas? The solution I've come up with (but which is yet to be
implemented) does not feel Ruby-ish at all and could probably be
implemented in pretty much any other programming language.
And no, this is not school work, no matter what you think.
-Deniz Dogan
I'm trying to come up with the "best", most Ruby-ish way to write a
method such as this one:
# This method replaces randomly selected characters in 'string' with new
# randomly selected characters of [A-Za-z0-9]. However, it does not
# replace any character with the character itself, i.e., it does not
# replace any "a" with "a". Also, no position in the string will ever be
# replaced twice.
# 'string' is the String to perform the replacing on.
# 'amount' is the amount of different characters to replace.
def random_replace(string, amount)
...
end
You don't have to care about any error checking of course.
Any ideas? The solution I've come up with (but which is yet to be
implemented) does not feel Ruby-ish at all and could probably be
implemented in pretty much any other programming language.
And no, this is not school work, no matter what you think.
-Deniz Dogan