From: Marcin Grzywaczewski Date: 2011-09-01T08:20:19+09:00 Subject: Re: how to pass a variable to a method in an existing class? "self" is a pointer to an actual element. So if you write: class String def convert self.upcase end end It'll be perfectly fine. Yours Martin 2011/9/1 yw hi : > Hi, > > I am a new ruby user and I want to add a function to an existing class. > I googled the answer and found part of the solution. All findings on the > web adding a new method without a variable. In my case I want to use the > string as a variable. Here is what I want to do: > class String > > def convert(x) > #code to convert the x > x.upcase > end > end > > What I want is in the irb I can use the new method in the way as: > > "a".convert > > This will convert a to upper case. However, it does not take the "a" as > the input variable and generating error > ArgumentError: wrong number of arguments (0 for 1) > > How do I acheive what I want? > > Thanks > > Frank > > -- > Posted via http://www.ruby-forum.com/. > >