« Back to Index

Ruby’s “Around Alias” pattern

View original Gist on GitHub

Ruby Around Alias Pattern.rb

class String
  alias :orig_length :length

  def length
    "Length of string '#{self}' is: #{orig_length}"
  end  
end

"abc".length
#=> "Length of string 'abc' is: 3"