1.9.3p125 :027 > a = "Hello"
=> "Hello"
1.9.3p125 :028 > -a
NoMethodError: undefined method `-@' for "Hello":String
from (irb):28
from ~/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `'
1.9.3p125 :029 >
1.9.3p125 :029 > def a.-@;downcase;end;
1.9.3p125 :036 > a
=> “Hello”
1.9.3p125 :037 > -a
=> “hello”
1.9.3p125 :038 >
#!/usr/local/ruby/bin/ruby
class String
def -@
downcase
end
def +@
upcase
end
def ~
# Do a ROT13 transformation - http://en.wikipedia.org/wiki/ROT13
tr 'A-Za-z', 'N-ZA-Mn-za-m'
end
def to_proc
Proc.new { self }
end
def to_a
[ self.reverse ]
end
end
str = "Teketa's Blog is GREAT"
puts "-#{str} = #{-str}"
puts "+#{str} = #{+str}"
puts "~#{str} = #{~str}"
puts "#{str}.to_a = #{str.to_a}"
puts %w{a, b}.map str
puts *str
-Teketa's Blog is GREAT = teketa's blog is great
+Teketa's Blog is GREAT = TEKETA'S BLOG IS GREAT
~Teketa's Blog is GREAT = Grxrgn'f Oybt vf TERNG
Teketa's Blog is GREAT.to_a = ["TAERG si golB s'atekeT"]
Teketa's Blog is GREAT
Teketa's Blog is GREAT
TAERG si golB s'atekeT