Created
December 17, 2010 19:20
-
-
Save kedarmhaswade/745535 to your computer and use it in GitHub Desktop.
Supposed to interesting, concise, clear and useful one-liners
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
# find methods of an Array that have ! equivalents: e.g. map (Note: the method /methods/ returns an Array of /Symbol/s) | |
[].methods.delete_if{|x| [].methods.index((x.to_s+"!").to_sym) == nil} | |
# => [:reverse, :rotate, :sort, :collect, :map, :select, :reject, :slice, :uniq, :compact, :flatten, :shuffle, :sort_by] | |
# find methods of a String that have ! equivalents: e.g. sub | |
"".methods.delete_if{|x| "".methods.index((x.to_s+"!").to_sym) == nil} | |
#=> [:succ, :next, :upcase, :downcase, :capitalize, :swapcase, :reverse, :sub, :gsub, :chop, :chomp, :strip, :lstrip, :rstrip, :tr, :tr_s, :delete, :squeeze, :slice, :encode] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment