# Undefined method

**URL:** <https://www.ruby-forum.com/t/undefined-method/146946>\
**Category:** Rails\
**Created:** [August 27, 2008, 1:09am UTC](https://www.ruby-forum.com/t/undefined-method/146946 "2008-08-27T01:09:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19b73/32.png) [@iga](https://www.ruby-forum.com/u/iga)\
**Post date:** [August 27, 2008, 1:09am UTC](https://www.ruby-forum.com/t/undefined-method/146946/1 "2008-08-27T01:09:27Z")

</div>

I’m trying to pass a method to another object/method as a variable.

Example one, login 1 works just fine.

def login1  
@driver.Login(username, password)  
end

However, if I try to pass “Login” to the driver as an argument  
(example two Login 2), I get “undefined method `command\_string’ for  
#SOAP::RPC::Driver:0x316dc28”

“Login” is a legit method for the SOAP::RPC::Driver. Do I need to do  
something to variable first?

def login2  
command\_string = “Login”  
send\_to\_api(command\_string)  
end

def send\_to\_api(command\_string)  
results = @driver.command\_string(username, password)  
end

---

<div class="post-metadata">

**Author:** ![iga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19b73/32.png) [@iga](https://www.ruby-forum.com/u/iga)\
**Post date:** [August 27, 2008, 1:15am UTC](https://www.ruby-forum.com/t/undefined-method/146946/2 "2008-08-27T01:15:18Z")

</div>

On Aug 26, 2008, at 7:08 PM, iga wrote:

> (example two Login 2), I get "undefined method `command\_string’ for  
> def send\_to\_api(command\_string)  
> results = @driver.command\_string(username, password)  
> end

While you need to be careful, you can do exactly that by using send.

def send\_to\_api(command\_string)  
@driver.send(command\_string, username, password)  
end

There’s no need to assign to results, the last expression evaluated is  
the return value of the method.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![iga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19b73/32.png) [@iga](https://www.ruby-forum.com/u/iga)\
**Post date:** [August 27, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/undefined-method/146946/3 "2008-08-27T14:51:04Z")

</div>

Thanks,

This appears to have worked. When you suggest the need to “be careful”  
what did you mean?

+bm

On Aug 26, 6:14 pm, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![iga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19b73/32.png) [@iga](https://www.ruby-forum.com/u/iga)\
**Post date:** [August 27, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/undefined-method/146946/4 "2008-08-27T15:22:07Z")

</div>

Through the use of Object#send any method can be invoked – even those  
that are protected or private. You usually need to have a good reason  
to circumvent the restrictions put in place by the class author.

For a SOAP application, you’re responsible for making sure that the  
methods that are called in this way are the “right” ones.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
