From: Tony Arcieri Date: 2010-06-02T23:24:55+09:00 Subject: Re: having a class method called only one time ? --000e0cd3aa2c7820c004880cdae1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You can "memoize" the result of such an operation in an instance variable b= y doing @cached_result ||=3D big_expensive_operation This will use the value of @cached_result unless it's unset/nil, otherwise it will invoke the expensive operation and store the result in an ivar 2010/6/2 Une B=E9vue > I'd like having a class method called only one time ? > Is it possible ? > > suppose i do have a class "HFSFile" and i need to know the host ip. > > i don't want to call the method giving host ip each time i need it but > only the first time even i do instantiate several HFSFile, mostly > because it's time consuming : > > @h[:host_ip] =3D `curl -s http://whatismyip.org`.chomp > > it is even in a while loop because sometimes curl returns ''. > > > -- > =AB Les faiblesses des hommes font la force des femmes. =BB > (Voltaire) > > --=20 Tony Arcieri Medioh! A Kudelski Brand --000e0cd3aa2c7820c004880cdae1--