Skip to content

Commit

Permalink
Added Class#alias_method:for:.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Sep 20, 2010
1 parent b650217 commit a9c2c86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/class.fnc
Expand Up @@ -52,4 +52,9 @@ def class Class {
}
}
}

def alias_method: new_method_name for: old_method_name {
"Defines an alias method for another method."
define_method: new_method_name with: (self method: old_method_name)
}
}
10 changes: 7 additions & 3 deletions src/bootstrap/class.cc
Expand Up @@ -173,10 +173,14 @@ second argument to serve as the method's body.",
method_block->override_self(true);
dynamic_cast<Class*>(self)->def_method(arg1->to_s(), method_block);
return t;
} else {
errorln("Class#define_method:with: expects String and Block arguments.");
return nil;
}
if(Method* method = dynamic_cast<Method*>(arg2)) {
dynamic_cast<Class*>(self)->def_method(arg1->to_s(), method);
return t;
}

errorln("Class#define_method:with: expects String and Callable arguments.");
return nil;
}

METHOD(ClassClass, undefine_method)
Expand Down
14 changes: 14 additions & 0 deletions tests/class.fnc
Expand Up @@ -371,4 +371,18 @@ FancySpec describe: Class with: |it| {
MyOuter::MyInner1 class_method1 should == MyOuter::MyInner1
MyOuter::MyInner2 class_method2 should == [MyOuter::MyInner1, MyOuter::MyInner2]
}

it should: "have an alias method as defined" for: 'alias_method:for: when: {
def class AClass {
def foo {
"in foo!"
}

alias_method: 'bar for: 'foo
}

obj = AClass new
obj foo should == "in foo!"
obj bar should == "in foo!"
}
}

0 comments on commit a9c2c86

Please sign in to comment.