OLW (One Liner of the Week): Character Filtering

We are kicking off a new series of crazy one-liners we have encountered. This one is a #rubyoneliner :
c.to_a.inject({}){|a, (k,v)| a[k[0]==’.’?k[1..-1]:k]=v.map{|v2| v2[0]==’.’?v2[1..-1]:v2}; a}
This function strips the starting periods from all the keys and values in a hash if they are present. It does this by converting the hash to an array, then remapping it to a hash wherein each value has the beginning periods stripped from the key and all values are iterated over to remove all periods, before returning the accumulated hash at the end of the line.
Have an even crazier one-liner you want to share? Let us know!
“I order the club sandwich all the time and I’m not even a member. I don’t know how I get away with it.” – Mitch Hedberg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s