From: Peter Zotov Date: 2012-06-07T07:54:55+09:00 Subject: Re: "Create a rock paper scissors program in ruby WITHOUT using conditionals" David D. писал 07.06.2012 02:50: > I'm in an introductory software development class, and my homework is > to > create a rock paper scissors program that takes two arguments (rock, > paper), etc, and returns the arg that wins. > > Now I would make quick work of this problem if I could use > conditionals, > but the assignment says everything we need to know is in the first > three > chapters of the ruby textbook, and these chapters DO NOT include > conditionals! Would it be possible to create this program without > them? > Or is he just expecting us to be resourceful and use the > conditionals. > It's a very easy assignment with conditionals though...I'm thinking > that > I might be missing something here. Instead of this: if arg == "a" 1 elsif arg == "b" 2 end ... you can use: { "a" => 1, "b" => 2 }[arg] I leave the rest to your imagination. -- WBR, Peter Zotov.