--20cf3001b8415fdccd049f2e8b6a Content-Type: text/plain; charset=ISO-8859-1 On Wed, Mar 23, 2011 at 6:52 PM, Jack W. <jack.whitman403 / gmail.com> wrote: > Hi all, > > Just started looking at Ruby the last couple of days, so as a starter I > tried to convert a little PHP function I've made into some ruby code. > > There is a more "ruby" way of doing things using blocks and gsub. Not the nicest code I've ever written and there's probably a better way, but try this for size. def caeserCipher(s, m d ue) m 26 m unless d s.gsub(/[a-z]/) {|x| ((x[0]+m-97)%26+97).chr} end Mac > But I get following error when I tried to run on Linux: > > > caesarCiper.rb:7:in `caesarCipher': undefined method `ord' for > "a":String (NoMethodError) > from caesarCiper.rb:5:in `each' > from caesarCiper.rb:5:in `caesarCipher' > from caesarCiper.rb:42 > > > I guess I need to make the c variable to a character before calling the > ord method on it? -but I don't know the method to do so. > Please help me, and please tell me if I'm wrong. > > Oh, and some of the rest of the code might be very wrong to - just can't > debug that untill this error is gone ;) > > - jack > > Attachments: > http://www.ruby-forum.com/attachment/6063/caesarCipher.php > http://www.ruby-forum.com/attachment/6064/caesarCiper.rb > > > -- > Posted via http://www.ruby-forum.com/. > > --20cf3001b8415fdccd049f2e8b6a--