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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 26, 2008, at 7:08 PM, iga wrote:> > 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) > endWhile 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
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 Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Aug 26, 2008, at 7:08 PM, iga wrote: > > > > > > > I''m trying to pass a method to another object/method as a variable. > > > Example one, login 1 works just fine. > > > def login1 > > -y6Ttphvx4OA2T6q+CZDnyA@public.gmane.org(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 > > While you need to be careful, you can do exactly that by using send. > > def send_to_api(command_string) > -Aziy4oF9jrTtiydaUZqy3w@public.gmane.org(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 Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > smime.p7s > 3KViewDownload--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org On Aug 27, 2008, at 8:48 AM, iga wrote:> 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 Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> On Aug 26, 2008, at 7:08 PM, iga wrote: >> >> >> >> >> >>> 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 >> >> 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 Biedenharn http://agileconsultingllc.com >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
undefined method `username'' for 1:Fixnum Extracted source (around line #3): 1: <% form_tag (:action => ''update_password'', :id => @user) do %> 2: <label> enter old password</label> 3: <%= password_field ''user'', ''username'' %><p> 4: 5: <label> enter new password</label> 6: <%= password_field ''user'', ''password'' %><p> I got above error run this program. please any one help me.. source: <% form_tag (:action => ''update_password'', :id => @user) do %> <label> enter old password</label> <%= password_field ''user'', ''username'' %><p> <label> enter new password</label> <%= password_field ''user'', ''password'' %><p> <label> enter confirm password</label> <%= password_field ''user'', ''new_password'' %><p> <%= submit_tag "Submit" %> <% end %> thanks, karthik -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Sep 2008, at 10:35, karthik reva wrote:> > undefined method `username'' for 1:Fixnum > > Extracted source (around line #3): > > 1: <% form_tag (:action => ''update_password'', :id => @user) do %> > 2: <label> enter old password</label> > 3: <%= password_field ''user'', ''username'' %><p> > 4: > 5: <label> enter new password</label> > 6: <%= password_field ''user'', ''password'' %><p> > > I got above error run this program. please any one help me.. >Sounds like @user is the number 1 whereas rails is expecting it to be something with a username, password and new_password methods (eg an instance of User) Fred> source: > > <% form_tag (:action => ''update_password'', :id => @user) do %> > <label> enter old password</label> > <%= password_field ''user'', ''username'' %><p> > > <label> enter new password</label> > <%= password_field ''user'', ''password'' %><p> > > <label> enter confirm password</label> > <%= password_field ''user'', ''new_password'' %><p> > <%= submit_tag "Submit" %> > > <% end %> > > thanks, > karthik > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- Change Password with acts_as_authenticated
- Problems With IO.popen
- df command shows transport endpoint mount error on gluster client v.3.10.5 + core dump
- df command shows transport endpoint mount error on gluster client v.3.10.5 + core dump
- df command shows transport endpoint mount error on gluster client v.3.10.5 + core dump