Override the method from String Class : String class Extension « String « Ruby
- Ruby
- String
- String class Extension
Override the method from String Class
class String
def scramble
(split //).sort_by { rand }.join
end
end
class UnpredictableString < String
def scramble
(split //).sort_by { rand }.join
end
def inspect
scramble.inspect
end
end
str = UnpredictableString.new("this is a test.")
puts str
Related examples in the same category