Hi all,
Last night I was playing with some third-party lib and found myself
having to type StupidlyLongLibName::LongModuleName::LongClassName
repeatedly and I wanted a mechanism where I could rename these classes
for my own use to cut down on the finger typing.
I thought I could just do:
class Shortname < OldLongClassName; end
Unfortunately this didn’t work (yes there’s no error thrown, but the
later code expected OldLongClassName and wouldn’t work with Shortname
So my request is:
a: is it possible to alias a class (I know you can do it with methods)?
b: if not can it be added (perhaps with aka)?
Thanks
Kev
Kevin J. [email protected] wrote:
So my request is:
a: is it possible to alias a class (I know you can do it with
methods)? b: if not can it be added (perhaps with aka)?
You can store that class in any variable or constant you like. So all
of
these work:
$cl = ::StupidlyLongLibName::LongModuleName::LongClassName
@cl = ::StupidlyLongLibName::LongModuleName::LongClassName
@@cl = ::StupidlyLongLibName::LongModuleName::LongClassName
cl = ::StupidlyLongLibName::LongModuleName::LongClassName
Cl = ::StupidlyLongLibName::LongModuleName::LongClassName
Note: depending on where in the code you are some of these do not really
make sense.
Kind regards
robert
On 9/28/06, Kevin J. [email protected] wrote:
Unfortunately this didn’t work (yes there’s no error thrown, but the
later code expected OldLongClassName and wouldn’t work with Shortname
So my request is:
a: is it possible to alias a class (I know you can do it with methods)?
b: if not can it be added (perhaps with aka)?
You can do this as well:
include StupidlyLongLibName::LongModuleName
however it all stuff from the said module.
Note: depending on where in the code you are some of these do not really
make sense.
That’s an amazingly intuitive comment - wish I’d made that /me ==
jealous…
Thanks for the rest of the insight, but this particular thing rings
true for just about any/all code
Kev
[email protected] wrote:
my favourite is
d, f, fu = Dir, File, FileUtils
since those three go together in verbose code so often.
w00t! Forget all those silly “constants”!
$d, $f, $fu = Dir, File, FileUtils
T.
On Thu, 28 Sep 2006, Robert K. wrote:
@@cl = ::StupidlyLongLibName::LongModuleName::LongClassName
cl = ::StupidlyLongLibName::LongModuleName::LongClassName
Cl = ::StupidlyLongLibName::LongModuleName::LongClassName
Note: depending on where in the code you are some of these do not really make
sense.
my favourite is
d, f, fu = Dir, File, FileUtils
since those three go together in verbose code so often.
-a
On 9/28/06, Trans [email protected] wrote:
w00t! Forget all those silly “constants”!
$d, $f, $fu = Dir, File, FileUtils
Much too readable
*x = Dir, File, FileUtils
who needs names!!!
Robert
T.