Anonymous user
Send an unknown method call: Difference between revisions
m
Python < Ruby. Link to runtime evaluation.
(Task rewrite but maintaining original intent.) |
m (Python < Ruby. Link to runtime evaluation.) |
||
Line 5:
;Cf:
* [[Respond to an unknown method call]].
* [[Runtime evaluation]]
=={{header|Python}}==▼
String literal "foo" may be replaced by any expression resulting in a string▼
<lang python>class Example(object):▼
def foo(self):▼
return 42▼
getattr(Example(), "foo")() # => 42</lang>▼
=={{header|Ruby}}==
<lang ruby>class Example▼
▲class Example
def foo
42
Line 21 ⟶ 28:
Example.new.send symbol # => 42
Example.new.send( :bar, 1, 2 ) { |x,y| x+y } # => 3</lang>
▲=={{header|Python}}==
▲String literal "foo" may be replaced by any expression resulting in a string
▲class Example(object):
▲ def foo(self):
▲ return 42
▲getattr(Example(), "foo")() # => 42</lang>
|