Class: Rot13
- Inherits:
-
Object
- Object
- Rot13
- Defined in:
- lib/rot13.rb
Overview
file: rot13.rb
Class Method Summary collapse
Class Method Details
.rotate(s, deg = 13) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rot13.rb', line 7 def self.rotate(s,deg=13) a = ('a'..'z').map.with_index{|x,i| [x.chr,i] } r = s.split(//).map do |x| item = a.assoc(x.downcase) c = item ? a.rotate(deg)[item.last].first : x x == x.downcase ? c : c.upcase end r.join end |