module Pigged
String.class_eval do
def pig
newstring = self + self[0]; newstring[0] = ""; newstring += "ay"
return newstring
end
end
end
is the relevant code. What I want to do is make a method, pig!, that modifies the original string. How do I do that, without modifying self, because that is not allowed…?
You shouldn’t modify self.
Use
replaceor a custom method.Read ‘Writing method “change!” for String‘ for more information.