From: Erik Boling Date: 2007-07-27T12:30:35+09:00 Subject: Re: Adding arrays Todd Benson wrote: > On 7/25/07, Erik Boling wrote: >> Great explination, and i did get the irb, thanks a ton todd :). > > No prob. If you really are just starting, don't get too frustrated > with "advanced" methods like zip and inject. They both are powerful, > but you can get by without them to start. For list-type objects > (Enumerable, Hash, Array, etc.), Ruby provides a swiss army knife of > methods to slice and dice them. Get to know your enumerables! Get > intimate with the String class, too! > > cheers, > Todd humm ok so i tried out my *program* but at the very end i get an error.. irb(main):001:0> def ask(question) irb(main):002:1> puts "#{question}:\n" irb(main):003:1> gets.split irb(main):004:1> end => nil irb(main):005:0> Var_1 = ask("Enter 1st Vendors prices") Enter 1st Vendors prices: 14.50 16.50 14 => ["14.50", "16.50", "14"] irb(main):006:0> Var_2 = ask("Enter 2nd vendors prices") Enter 2nd vendors prices: 13 17.50 14 => ["13", "17.50", "14"] irb(main):007:0> Var_1.zip(Var_2) => [["14.50", "13"], ["16.50", "17.50"], ["14", "14"]] irb(main):008:0> Var_1.zip(Var_2).map{ |pair| pair[0] - pair[1] } NoMethodError: undefined method `-' for "14.50":String from (irb):8 from (irb):8:in `map' from (irb):8 from :0 irb(main):009:0> could it because im using floats, and not intergers? -- Posted via http://www.ruby-forum.com/.