D
darren kirby
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
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