Redefining Backquotes : alias « Method « Ruby






Redefining Backquotes


alias old_backquote ` 
def `(cmd) 
    result = old_backquote(cmd) 
    if $?!= 0 
        fail "Command #{cmd} failed: #$?" 
    end 
    result 
end 
print `date` 
print `data` 

 








Related examples in the same category

1.Give length a new name
2.Alias a old method a new name, then change the implementation of old method
3.Create a Wrapper method to alias
4.Aliasing Methods