Send an unknown method call: Difference between revisions

Task rewrite but maintaining original intent.
m (→‎{{header|Ruby}}: fixed alignment)
(Task rewrite but maintaining original intent.)
Line 1:
{{draft task|Object oriented}}
 
Send a message toInvoke an object withoutmethod knowingwhere the name of the message.method Seeto alsobe [[Respondinvoked tocan anbe unknowngenerated methodat call]]run time.
 
;Cf:
* [[Respond to an unknown method call]].
 
=={{header|Ruby}}==
 
<lang ruby>
<pre>
class Example
def foo
Line 17 ⟶ 20:
symbol = :foo
Example.new.send symbol # => 42
Example.new.send( :bar, 1, 2 ) { |x,y| x+y } # => 3</lang>
</pre>
 
=={{header|Python}}==
String literal "foo" may be replaced by any expression resulting in a string
 
<lang python>
<pre>
class Example(object):
def foo(self):
return 42
getattr(Example(), "foo")() # => 42</lang>
</pre>
Anonymous user