Skip to content

Instantly share code, notes, and snippets.

@JulesWang
Created October 4, 2011 14:54
Show Gist options
  • Save JulesWang/1261839 to your computer and use it in GitHub Desktop.
Save JulesWang/1261839 to your computer and use it in GitHub Desktop.
class SortAlogrithm
def quick_sort
#...
puts "quick_sort"
end
def bubble_sort
#...
puts "bubble_sort"
end
end
sa = SortAlogrithm.new
option = "quick_sort"
# Two ways to call fun in runtime with ease
sa.__send__ option.to_sym
eval("sa."+option)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment