Skip to content

Instantly share code, notes, and snippets.

@semaperepelitsa
Created July 10, 2012 08:06
Show Gist options
  • Save semaperepelitsa/3081956 to your computer and use it in GitHub Desktop.
Save semaperepelitsa/3081956 to your computer and use it in GitHub Desktop.
p ["foo", "bar"].map(&:upcase) # nice
p ["foo", "bar"].map{ |s| s.sub(/[a-z]/, '') } # ugh
class Underscore < BasicObject
def method_missing(name, *args)
::Kernel.lambda{ |a| a.public_send(name, *args) }
end
end
UNDERSCORE = Underscore.new
def _; UNDERSCORE end
p ["foo", "bar"].map(&_.sub(/[a-z]/, '')) # nice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment