From: Mike Onofrietto Date: 2012-07-12T05:14:40+09:00 Subject: Re: how do I call a method with a period and pass the object before it ? This is exactly what I was looking for. Thanks ! In other lingo 5 is the receiver, and add_argument(10) is the message correct ? Thiago Massa wrote in post #1067792: > 1.9.2p290 :011 > class Fixnum > 1.9.2p290 :012?> def add_argument(arg) > 1.9.2p290 :013?> return self+arg > 1.9.2p290 :014?> end > 1.9.2p290 :015?> end > => nil > 1.9.2p290 :016 > 5.add_argument(10) > => 15 > > What you do is add the method you want to Fixnum(which is the 1.class > class), ruby have open classes so you can add methods on the fly for it. > > Now create the method, using the example for 5.add_argument(10), 5 is > self, > 10 is arg. So to "get the number before the point" use self. > > In order to chain methods(in case you want to do > 5.add_argument(10).drink_coke.have_fun, return self. -- Posted via http://www.ruby-forum.com/.