Skip to content

Instantly share code, notes, and snippets.

@kedarmhaswade
Created December 17, 2010 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedarmhaswade/745535 to your computer and use it in GitHub Desktop.
Save kedarmhaswade/745535 to your computer and use it in GitHub Desktop.
Supposed to interesting, concise, clear and useful one-liners
# 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