Send an unknown method call: Difference between revisions

Content added Content deleted
m (Python < Ruby. Link to runtime evaluation.)
(take an argument for fun)
Line 10: Line 10:
String literal "foo" may be replaced by any expression resulting in a string
String literal "foo" may be replaced by any expression resulting in a string
<lang python>class Example(object):
<lang python>class Example(object):
def foo(self):
def foo(self, x):
return 42
return 42 + x

name = "foo"
getattr(Example(), "foo")() # => 42</lang>
getattr(Example(), name)(5) # => 47</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==