Skip to content

Instantly share code, notes, and snippets.

@edvardm
Created November 8, 2012 10:56
Show Gist options
  • Save edvardm/4038157 to your computer and use it in GitHub Desktop.
Save edvardm/4038157 to your computer and use it in GitHub Desktop.
map helper
module BlockHelper
def map_args(method_name)
map(&method(method_name.to_sym))
end
def each_args(method_name)
each(&method(method_name.to_sym))
end
end
Array.send(:include, BlockHelper)
Hash.send(:include, BlockHelper)
def double(n); 2*n; end
[1, 2, 3].map_args(:double)
[2, 4, 6]
[1, 2, 3].each_args(:puts)
1
2
3
def double_val((k, v)); 2*v; end => nil
{'foo' => 42}.map_args(:double_val)
[84]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment