Send an unknown method call: Difference between revisions

take an argument for fun
m (Python < Ruby. Link to runtime evaluation.)
(take an argument for fun)
Line 10:
String literal "foo" may be replaced by any expression resulting in a string
<lang python>class Example(object):
def foo(self, x):
return 42 + x
 
name = "foo"
getattr(Example(), "foo"name)(5) # => 4247</lang>
 
=={{header|Ruby}}==
Anonymous user