Skip to content

Commit

Permalink
implement Method#curry, add comments to failing example, remove work…
Browse files Browse the repository at this point in the history
…ing examples from tags file
  • Loading branch information
tak1n committed May 28, 2015
1 parent f21d58d commit 6304e7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions kernel/common/method.rb
Expand Up @@ -141,6 +141,12 @@ def to_proc
Proc.from_method self
end

##
# Calls curry on the method in proc representation
def curry(n = nil)
to_proc.curry(n)
end

##
# Detach this Method from the receiver object it is bound to and create an
# UnboundMethod object. Populates the UnboundMethod with the method data as
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/method/curry_spec.rb
Expand Up @@ -25,7 +25,15 @@ def x.foo(a,b,c); [a,b,c]; end

it "raises ArgumentError when the method requires less arguments than the given arity" do
lambda { @obj.method(:zero).curry(1) }.should raise_error(ArgumentError)

# a method with one optional param would be something like: lambda { |a,b=nil| a + (b||0) }
# which doesn't work on rubinius:
# irb(main):002:0> b = lambda { |a,b=nil| a + (b||0) }
# Error validating bytecode: more arguments than local slots
# Rubinius::Internal: invalid bytecode method
lambda { @obj.method(:one_req_one_opt).curry(3) }.should raise_error(ArgumentError)

# same as above optional param in lambda/proc
lambda { @obj.method(:two_req_one_opt_with_block).curry(4) }.should raise_error(ArgumentError)
end

Expand Down
3 changes: 0 additions & 3 deletions spec/tags/ruby/core/method/curry_tags.txt
@@ -1,4 +1 @@
fails:Method#curry returns a curried proc
fails:Method#curry with optional arity argument returns a curried proc when given correct arity
fails:Method#curry with optional arity argument raises ArgumentError when the method requires less arguments than the given arity
fails:Method#curry with optional arity argument raises ArgumentError when the method requires more arguments than the given arity

0 comments on commit 6304e7d

Please sign in to comment.