-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove some hard coding in return value
- Loading branch information
1 parent
a4c1929
commit d39ce66
Showing
6 changed files
with
46 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') | ||
require 'multi-methods' | ||
require 'multi_methods' | ||
|
||
require 'spec/expectations' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module MultiMethods | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
class ImplementationCapture | ||
attr_accessor :methods | ||
def initialize | ||
@methods = {} | ||
end | ||
def router | ||
|
||
end | ||
def implementation_for symbol, &block | ||
@methods[symbol] = block | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def multi_method name, &block | ||
implementation = ImplementationCapture.new | ||
implementation.instance_eval(&block) | ||
define_method name, implementation.methods[:hello_world] | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
|
||
class Foo | ||
class HelloWorldReturner | ||
include MultiMethods | ||
|
||
multi_method :bar do | ||
multi_method :hello_world do | ||
router {|*args| :hello_world} | ||
implementation_for :hello_world do | ||
'you worked' | ||
end | ||
end | ||
end | ||
|
||
class HelloWorldReturner | ||
class HelloWorldReturner2 | ||
include MultiMethods | ||
|
||
multi_method :hello_world do | ||
router {|*args| :hello_world} | ||
implementation_for :hello_world do | ||
'you worked' | ||
'another return' | ||
end | ||
end | ||
end | ||
|
||
describe MultiMethods do | ||
|
||
context "getting it compiling" do | ||
it "allows me to include and call on a class" do | ||
Foo.new | ||
end | ||
end | ||
|
||
context "calling the created method" do | ||
it "has the method" do | ||
Foo.new.bar | ||
end | ||
it "returns the appropriate value" do | ||
HelloWorldReturner.new.hello_world.should == "you worked" | ||
HelloWorldReturner2.new.hello_world.should == "another return" | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters