From: Thiago Massa Date: 2012-07-07T22:01:27+09:00 Subject: Re: how do I call a method with a period and pass the object before it ? --e89a8f83ac5175f52804c43cfadc Content-Type: text/plain; charset=ISO-8859-1 Oh, what i mean by point is the dot or period. On Sat, Jul 7, 2012 at 9:58 AM, Thiago Massa wrote: > 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. > > On Sat, Jul 7, 2012 at 8:06 AM, roob noob wrote: > >> like 1.to_s , except I want 8.bits_to_bytes >> >> I know how to do it like bits_to_bytes(8) but I think that does not look >> nearly as good. I know this is possible but I only pass the >> bits_to_bytes(8) way so far. >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > --e89a8f83ac5175f52804c43cfadc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Oh, what i mean by point is the dot or period.

On Sat, Jul 7, 2012 at 9:58 AM, Thiago Massa <thiagown@gmail.com> wrote:
1.9.2p290 :011 > c= lass Fixnum
1.9.2p290 :012?> =A0 def add_argument(arg)
1.9.2p290 :013?> =A0 =A0 return self+arg
1.9.2p290 :014?> =A0 =A0 end
1.9.2p290 :015?> =A0 end<= /div>
=A0=3D> nil=A0
1.9.2p290 :016 > 5.add_argument(10)
=A0=3D> 15

What you do is add the method you = want to Fixnum(which is the 1.class class), ruby have open classes so you c= an add methods on the fly for it.

Now create the method, using the example for 5.add_argument(10), 5 is s= elf, 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.

On Sat, Jul 7, 2012 = at 8:06 AM, roob noob <lists@ruby-forum.com> wrote:
like 1.to_s , except I want 8.bits_to_bytes

I know how to do it like bits_to_bytes(8) but I think that does not look nearly as good. I know this is possible but I only pass the
bits_to_bytes(8) way so far.

--
Posted via http://= www.ruby-forum.com/.



--e89a8f83ac5175f52804c43cfadc--