I was just sitting on the couch tonight after a long Saturday and not thinking about backwards names at all. I had my laptop open to get some work done, but my son sat down next to me, and I wanted to show him some programming.
I started out in irb and just did some simple string substitution with his name, but irb and ruby make it so easy to just mess around that I ended up with an implementation of Backwards Names before I knew it.
Here it is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def backwards_name(name) | |
name.split(/ +/) | |
.map { |piece| piece = piece.reverse; "#{piece[0].upcase}#{piece[1..-1].downcase}" } | |
.join(" ") | |
end | |
>> backwards_name "John Sumsion" | |
=> "Nhoj Noismus" |
It was just really fun to do that with him and see lights start to turn on about what programming was like.
No comments:
Post a Comment