Hello I have an method like this: def test(x, y='''', z='''') puts "x=#{x} y=#{y} z=#{z}" end and I want call with x and z parameters: test(''x'', z=''z'') output: x=''x'' y=''z'' z='''' How you can see, the Z value appears in Y parameter... and I want call just with X and Z parameters Thanks a lot! Cassiano Roloff RS - Brazil --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is a ruby question rather than a rails question. Anyway, ruby doesn''t have named parameters, you you just can''t do that. You''re passing z=''z'' as the second argument, which evaluates to ''z'' and so y is set to ''z''. With ruby''s default arguments stuff you must pass in the leftmost n parameters, for some value of n. (ie no ''gaps'') Fred -- 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 -~----------~----~----~----~------~----~------~--~---
You can always simulate it by passing in a hash: def test(in_hsh={}) puts "x=#{in_hsh[''x'']} y=#{in_hsh[''y'']} z=#{in_hsh[''z'']}" end test({''x'' => ''x'', ''z'' => ''z'') Cassiano Roloff wrote:> Hello > > I have an method like this: > def test(x, y='''', z='''') > puts "x=#{x} y=#{y} z=#{z}" > end > > and I want call with x and z parameters: > test(''x'', z=''z'') > output: > x=''x'' y=''z'' z='''' > > How you can see, the Z value appears in Y parameter... > and I want call just with X and Z parameters > > Thanks a lot! > > Cassiano Roloff > RS - Brazil > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---