Alias a old method a new name, then change the implementation of old method
class Array
alias :length_old :length
def length
return length_old / 2
end
end
array = [1, 2, 3, 4]
array.length # => 2
array.size # => 4
array.length_old # => 4
class Array
alias :length :length_old
end
array.length # => 4
Related examples in the same category