I can''t figure out what is going wrong. In a helper I have this line: elsif player.send(next_period) == (''none'' || ''bench'' ) html_holder << " O" This works for "none" but doesn''t seem to work for "bench". I have double checked to make sure the attribute is set to exactly ''bench'' with no spaces or case differences. Is the condition syntax correct? can I go: if x == (''none'' || ''one'' || ''two'' || ''three'') or should I be doing it differently? I suppose I could be using a regular expression but an even more desirable way would be to test a string against a simple array of string options. I''ve thumbed through my ruby books but couldn''t find the answer. -- 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 -~----------~----~----~----~------~----~------~--~---
2008/1/12, Tom Norian <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > In a helper I have this line: > > elsif player.send(next_period) == (''none'' || ''bench'' ) > html_holder << " O"See Array#include? %w(none bench).include?(player.send(next_period))> This works for "none" but doesn''t seem to work for "bench". I have > double checked to make sure the attribute is set to exactly ''bench'' with > no spaces or case differences. > > Is the condition syntax correct? can I go: > > if x == (''none'' || ''one'' || ''two'' || ''three'') > > or should I be doing it differently?%w(none one two three).include? x -- Jean-François. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you -- 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 Jan 12, 2008, at 1:35 PM, Tom Norian wrote:> > Is the condition syntax correct? can I go: > > if x == (''none'' || ''one'' || ''two'' || ''three'') >I don''t know if this is the preferred way, but I''d do if [''none'', ''one'', ''two'', ''three''].include?(x) Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 1/12/08, Phillip Koebbe <phillipkoebbe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jan 12, 2008, at 1:35 PM, Tom Norian wrote: > > > > Is the condition syntax correct? can I go: > > > > if x == (''none'' || ''one'' || ''two'' || ''three'') > > > > I don''t know if this is the preferred way, but I''d do > > if [''none'', ''one'', ''two'', ''three''].include?(x)Or since we''re talking all Strings here if x =~ /^(none|one|two|three)$/ -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 Jan 2008, at 19:35, Tom Norian wrote:> > I can''t figure out what is going wrong. > > In a helper I have this line: > > elsif player.send(next_period) == (''none'' || ''bench'' ) > html_holder << " O" > > This works for "none" but doesn''t seem to work for "bench". I have > double checked to make sure the attribute is set to exactly ''bench'' > with > no spaces or case differences. > > Is the condition syntax correct? can I go: > > if x == (''none'' || ''one'' || ''two'' || ''three'')for reference, the reason this doesn''t work is that ruby first evaluates ''none'' || ''one'' || ''two'' || ''three'' which evaluates to ''none'' (since ''none'' is not nil, the || stops there. So the above is the same as if x == ''none'' Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---