On 17/06/06, Bojan Mihelac <lists / mihelac.org> wrote:
> Do I do something wrong here or I cannot override method upcase in String?
>
> class String
>    def upcase
>      super.upcase
>    end
> end

super is used on its own in a subclass, and indicates the superclass's
method of the same name:

class MyString < String
  def upcase
    super + '!11'
  end
end

s = MyString.new('aol')
s.upcase # => 'AOL!11'

To modify the original class, use alias_method:

class String
  alias_method :original_upcase, :upcase
  def upcase
    original_upcase + '!ELEVEN'
  end
end

s = "myspace"
s.upcase # => "MYSPACE!ELEVEN"

I hope that clears it up a bit.

Paul.