On 5/18/06, Patrick Hurley <phurley / gmail.com> wrote: > On 5/18/06, viswesh <visweshwar_03 / rediffmail.com> 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. Hi Viswesh, you can find documentation, including usage for `casecmp` here: http://www.ruby-doc.org/core/classes/String.html#M001839 Have a quick look at this documentation, it will answer a lot of your questions. It's available for the entire core classes here: http://www.ruby-doc.org/core/ and for the standard library included with ruby here: http://www.ruby-doc.org/stdlib/ Cheers, -tim > > > > 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 > >