From: Patrick Hurley Date: 2006-05-18T22:27:12+09:00 Subject: Re: Please answer to this code? On 5/18/06, viswesh wrote: > Hi Mike, > > Thanks for ur time. > my intent of doing working on this code is : > as u can see the name prints if u give the name then after that if the > user types "good" or "ok" or "fine" or "wonderfull" he should be > prompted with saying Good buddy. else with "oh iam sorry".. > ***irrespective of case(i.e either uppercase or lowercase). > > i heard abt the casecmp() but usage of it 's not clear to me.. it would > be great if u could use that method in this code. > > thanx in advance.. > > > Mike Nelson wrote: > > viswesh wrote: > >> can u suggest me how to write a method where both cases are accepted to > >> a given string and that method i want to refer in the below program... > > > > I'm not too sure what you are asking for. Something like this? > > > > puts " what is your name" > > name = gets.chomp > > > > def checkIfGood(string) > > if string == "good" > > " good buddy" > > else > > "oh iam sorry" > > end > > end > > > > puts " hello #{name} how are you" > > puts checkIfGood(gets.chomp) > > > -- > Posted via http://www.ruby-forum.com/. > > You can use regular expressions for case insensitivity or downcase the string - regular expressions have the benefit of being far more flexible... # note with the regexp, unless we test for its absence we can forgo the chomp happy = case gets when /not.*good/i : false when /good/i : true when /ok/i : true when /fine/i : true when /wonderful/i : true else false # am I the only one that feels that the : should be allowed here for symmetry end puts happy ? "Good buddy" : "oh i am sorry" Hope that helps pth