Aliasing and the back-quote


(Robert Peirce) #1

On page 232 of the Ruby book, there is the following code:

alias :cmd :`
cmd “date”

which works. However,

` “date”

does not work, although

"date"

does. Why does cmd work without a second back-quote while a single
back-quote does not work at all?

Bob Peirce Venetia, PA
724-941-6883
bob@peirce-family.com [HOME (Mac)]
rbp@cooksonpeirce.com [OFFICE]

There is only one basic human right, the right to do as you damn well
please. And with it comes the only basic human duty, the duty to take
the consequences. – P.J. O’Rourke


(HAL 9000) #2

Robert Peirce wrote:

On page 232 of the Ruby book, there is the following code:

alias :cmd :`
cmd “date”

which works. However,

` “date”

does not work, although

"date"

does. Why does cmd work without a second back-quote while a single
back-quote does not work at all?

My best guess would be something like this:

The bactick is a special case, with a special syntax. It’s the only
method (I can think of) that is called by two syntactic instances
surrounding its argument. This is for historical reasons. It’s all
handled in the parser as a special case.

If you alias this “unusual” name to a “normal” name, they will both
behave as they normally would, with no special treatment either way.

Does this non-answer make any sense?

Hal