[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

override def method in CGI class, without altering the class!??????

Jer A

5/24/2007 12:25:00 AM


hello all,

I am a newbie to ruby.

how do I override a method from a particular class (in std class lib), just
for one program, without modifying the class.

Thanks in advance for all your help.

-Jer A.

_________________________________________________________________
Fight Allergies With Live Search
http://search.live.com/results.aspx?q=Remedies+For+Spring+Allergies&mkt=en-ca&F...


2 Answers

highlyjhi

5/24/2007 2:25:00 AM

0

Just re-write it in your program where it's needed.

class Foo
def bar
//method to override
end
end

Very simple.

- Jer H.


On May 23, 2007, at 8:25 PM, Jer A wrote:

>
> hello all,
>
> I am a newbie to ruby.
>
> how do I override a method from a particular class (in std class
> lib), just for one program, without modifying the class.
>
> Thanks in advance for all your help.
>
> -Jer A.
>
> _________________________________________________________________
> Fight Allergies With Live Search http://search...
> results.aspx?q=Remedies+For+Spring+Allergies&mkt=en-ca&FORM=SERNEP
>
>


Dan Zwell

5/24/2007 6:06:00 AM

0

highlyjhi wrote:
> Just re-write it in your program where it's needed.
>
> class Foo
> def bar
> //method to override
> end
> end
>
> Very simple.
>
> - Jer H.
>
>
> On May 23, 2007, at 8:25 PM, Jer A wrote:
>
>>
>> hello all,
>>
>> I am a newbie to ruby.
>>
>> how do I override a method from a particular class (in std class lib),
>> just for one program, without modifying the class.
>>
>> Thanks in advance for all your help.
>>
>> -Jer A.
>>
>> _________________________________________________________________
>> Fight Allergies With Live Search
>> http://search.live.com/results.aspx?q=Remedies+For+Spring+Allergies&mkt=en-ca&F...
>>
>>
>>
>
>
>

Just to clarify, you can define or redefine methods of core classes:

Class String
def inspect
"This string's value is \"#{self}\""
end
end