Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo():
- def my_method(self):
- return 3107
- class Bar():
- def my_method(self):
- return 7013
- def factory(klass):
- if klass == 'Foo':
- return Foo()
- elif klass == 'bar':
- return Bar()
- factory('Foo').my_method()
- => 3107
- OR
- print 'Foo'.constantize.my_method()
- => 3107
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement