class String
Public Instance Methods
isanagram?(base)
click to toggle source
# File lib/simplescrambler.rb, line 36 def isanagram?(base) if base.class != String raise NotString else one = self.chars two = base.chars if one.sort == two.sort return true else return false end end end
scramble(min = 10, max = 100)
click to toggle source
# File lib/simplescrambler.rb, line 4 def scramble(min = 10, max = 100) if max.class != Integer || min.class != Integer raise NotNumber elsif self.length == 1 raise CannotScrambleStringLetter elsif self.chars.count(self.chars[0]) == self.length raise CannotScrambleStringSame elsif min > 0 && max >= min temp = self.chars (min + rand(max - min + 1)).times do random = rand(temp.length) random2 = rand(temp.length) if random2 == random until random2 != random random2 = rand(temp.length) end end onepos = random random = temp[random] twopos = random2 random2 = temp[random2] temp[onepos] = random2 temp[twopos] = random end return temp.join elsif min <= 0 raise TooSmall elsif max < min raise MinMaxMismatch end end