Created
October 4, 2011 14:54
-
-
Save JulesWang/1261839 to your computer and use it in GitHub Desktop.
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
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