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

Discussion in 'Ruby' started by Jer A, May 24, 2007.

  1. Jer A

    Jer A Guest

    Jer A, May 24, 2007
    #1
    1. Advertising

  2. Jer A

    highlyjhi Guest

    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&FORM=SERNEP
    >
    >
     
    highlyjhi, May 24, 2007
    #2
    1. Advertising

  3. Jer A

    Dan Zwell Guest

    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&FORM=SERNEP
    >>
    >>
    >>

    >
    >
    >


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

    Class String
    def inspect
    "This string's value is \"#{self}\""
    end
    end
     
    Dan Zwell, May 24, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    837
    Jiong Feng
    Nov 19, 2003
  2. Sean Ross
    Replies:
    3
    Views:
    126
    Aredridel
    Dec 25, 2003
  3. Replies:
    7
    Views:
    162
  4. planetthoughtful

    Newbie: def must come before call to def?

    planetthoughtful, Mar 12, 2007, in forum: Ruby
    Replies:
    4
    Views:
    130
    Pit Capitain
    Mar 12, 2007
  5. Kyung won Cheon
    Replies:
    0
    Views:
    208
    Kyung won Cheon
    Nov 21, 2008
Loading...

Share This Page