# Undefining a method?

**URL:** <https://www.ruby-forum.com/t/undefining-a-method/92098>\
**Category:** Ruby\
**Created:** [April 16, 2007, 2:51am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098 "2007-04-16T02:51:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 2:51am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/1 "2007-04-16T02:51:24Z")

</div>

Is it possible to undefine a method. For example:

class A  
def method  
end  
end

A.undefine\_method(:method)

Is this possible?

I need to do this because I’m dynamically building methods into a class  
and it would make everything cleaner.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 3:05am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/2 "2007-04-16T03:05:28Z")

</div>

undef :method

irb(main):001:0\> def cow  
irb(main):002:1\> p “cow”  
irb(main):003:1\> end  
=\> nil  
irb(main):004:0\> cow  
“cow”  
=\> nil  
irb(main):005:0\> undef :cow  
=\> nil  
irb(main):006:0\> cow  
NameError: undefined local variable or method `cow’ for main:Object  
from (irb):6  
irb(main):007:0\>

Stephen B. IV

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 4:06am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/3 "2007-04-16T04:06:31Z")

</div>

You have two choices:

- undef\_method
- remove\_method

The first prevents any and all calls to the passed in method; the  
latter removes the method for just the given module which allows calls  
to be made into the superclass.

See the docs: ri undef\_method

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 4:34am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/4 "2007-04-16T04:34:33Z")

</div>

Dear All …

which one is the most recomended for Install from SVN ?  
Is it the “branch” or “Trunk” ?

And what is “tags” anyway ?

Sincerely  
-bino-

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 4:39am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/5 "2007-04-16T04:39:34Z")

</div>

bino\_oetomo wrote:

> Dear All …
> 
> which one is the most recomended for Install from SVN ?  
> Is it the “branch” or “Trunk” ?
> 
> And what is “tags” anyway ?
> 
> Sincerely  
> -bino-

Read here, you might know your answer:  
[http://eigenclass.org/hiki/bounded+space+instance\_exec](http://eigenclass.org/hiki/bounded+space+instance_exec)

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [April 16, 2007, 4:58am UTC](https://www.ruby-forum.com/t/undefining-a-method/92098/6 "2007-04-16T04:58:34Z")

</div>

On 4/15/07, bino\_oetomo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dear All …
> 
> which one is the most recomended for Install from SVN ?  
> Is it the “branch” or “Trunk” ?

Typically, you want the code from ‘Trunk’. It’s the main development  
‘branch’.

> And what is “tags” anyway ?

The following is based on Pragmatic Version Control  
[http://www.pragmaticprogrammer.com/titles/svn/index.html](http://www.pragmaticprogrammer.com/titles/svn/index.html)

TAGS:

What are they?  
A way to mark a static copy of set of files. The set of files can  
come from various versions in your repository. Tags take up very  
little room since they’re essentially just a set of pointers to  
existing files/diffs.

When should I use them?  
Use tags to mark releases. They give you a way to rebuild any given  
release (in case a client deletes it, etc.). You can also use them to  
check a release out to a branch for bug fixing, or adding new  
features.

Anything else I should know?  
If you need to edit the files, make a branch.

BRANCHES:

What are they?  
As the name implies, it’s a branch from the main ‘Trunk’ dir (where  
you do your core development). They allow you to run parallel  
development where you can make minor changes and release the branch,  
but continue full development on the trunk.

When should I use them?  
Releases, experiments, bug fixes.

When you’re about to do a release, make a release branch, make any  
changes that you don’t want in your ‘trunk’. When you actually  
publish the code, you should tag it as a release

If you’re thinking about making massive changes, you can use a branch  
for it. If you like the changes, merge them back into the trunk, if  
not, keep them as a history, or kill them if you like.

When you get a bug report, make a new branch for tracking it. Tag it  
before you do the fix, and tag it again after you’ve done the fix,  
then merge the fix back into the trunk.

Anything else I should know?  
Naming conventions are key. Here’s what the book suggests:

(forgive the formatting, or lack of it, gmail doesn’t use fix width  
fonts)

Event Style Example Type \*  
Release Branch RB-rel RB-1.0 Branch  
Releases REL-rel REL-1.0 Tag  
Bug fix Branch BUG-track BUG-3035 Branch  
Pre-bug fix PRE-track PRE-3035 Tag  
Post-bug fix POST-track POST-3035 Tag  
Experiments TRY-dev-desc TRY-no-db Branch

- This is not in the book, it’s just my best guess of what they should  
be.

> Sincerely  
> -bino-

hth
