Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
class Hash
def hash_map()
result = self.inject({}) do |hash, (k, v)|
hash.merge(yield(k, v))
end
end
end
{:a => 1, :b => 2}.hash_map {|k,v| {k.to_s*2, v*2}} # => {"aa"=>2, "bb"=>4}