Method names and alias



Hello all,

In Unix, you can create a symlink to an executable, and have the program
behave differently depending on how it was called by testing argv[0]. I would
like to do something similar with Ruby methods using alias.

I have many methods which come in pairs, a version each for signed and
unsigned numbers. These methods differ by only one line, eg:

def load_byte(destination, base_address, offset)
<snip 15 lines>
@registers.gen[destination] = bitstring_to_int(byte)
true
end

def load_byte_unsigned(destination, base_address, offset)
<snip 15 lines>
@registers.gen[destination] = bitstring_to_int(byte, signed=false)
true
end

My code would be considerably DRYer if I could make 'load_byte_unsigned' an
alias to 'load_byte', and have the method inspect the name it was called as
to decide if it should run 'bitstring_to_int(byte, signed=false)' or not.

Is there a way to do this?

If not, I suppose my best bet is to move the snipped 15 lines to
a 'load_byte_common' method and make 'load_byte' and 'load_byte_unsigned'
thin wrappers around it?

Thanks for consideration,
-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

.



Relevant Pages

  • Re: In the Shallow End
    ... and the compiler can ... Unix, qua Unix, provides very little in the ... you'd have known why it is easier to do in UNIX compared to Windows NT and its later revisions. ...
    (comp.sys.mac.advocacy)
  • Re: Great SWT Program
    ... hours using, or trying to use, Windows and its applications than ... semantically equivalent to the shell. ... I think you mentioned not having access to a Unix system. ...
    (comp.lang.java.programmer)
  • Re: Best practice for TOD clock
    ... > notice that my local time isn't exactly five hours offset from the TOD ... > clock -- this is because the TOD clock drifts over time (we don't have ... that controls both Classic and the default for z/OS Unix (when ...
    (bit.listserv.ibm-main)
  • Re: Micro$haft desperate! Buy Windoze 7, get (virtual) XP free!
    ... it's compatible by looking it up in the XCode online help? ... I always though the Unix cert was pretty much useless. ... Microsoft Windows: Java on Solaris has to translate to UTF-8, but on Windows it doesn't need to do that. ...
    (comp.sys.mac.advocacy)
  • Re: Authentication (was Re: Great SWT Program)
    ... reason I can't fix the terminal settings. ... then it's no wonder he hates Unix; ... I eventually set up my own MUD server, ...
    (comp.lang.java.programmer)