Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6304e7d

Browse files
committedMay 28, 2015
implement Method#curry, add comments to failing example, remove working examples from tags file
1 parent f21d58d commit 6304e7d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
 

Diff for: ‎kernel/common/method.rb

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def to_proc
141141
Proc.from_method self
142142
end
143143

144+
##
145+
# Calls curry on the method in proc representation
146+
def curry(n = nil)
147+
to_proc.curry(n)
148+
end
149+
144150
##
145151
# Detach this Method from the receiver object it is bound to and create an
146152
# UnboundMethod object. Populates the UnboundMethod with the method data as

Diff for: ‎spec/ruby/core/method/curry_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ def x.foo(a,b,c); [a,b,c]; end
2525

2626
it "raises ArgumentError when the method requires less arguments than the given arity" do
2727
lambda { @obj.method(:zero).curry(1) }.should raise_error(ArgumentError)
28+
29+
# a method with one optional param would be something like: lambda { |a,b=nil| a + (b||0) }
30+
# which doesn't work on rubinius:
31+
# irb(main):002:0> b = lambda { |a,b=nil| a + (b||0) }
32+
# Error validating bytecode: more arguments than local slots
33+
# Rubinius::Internal: invalid bytecode method
2834
lambda { @obj.method(:one_req_one_opt).curry(3) }.should raise_error(ArgumentError)
35+
36+
# same as above optional param in lambda/proc
2937
lambda { @obj.method(:two_req_one_opt_with_block).curry(4) }.should raise_error(ArgumentError)
3038
end
3139

Diff for: ‎spec/tags/ruby/core/method/curry_tags.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
fails:Method#curry returns a curried proc
2-
fails:Method#curry with optional arity argument returns a curried proc when given correct arity
31
fails:Method#curry with optional arity argument raises ArgumentError when the method requires less arguments than the given arity
4-
fails:Method#curry with optional arity argument raises ArgumentError when the method requires more arguments than the given arity

0 commit comments

Comments
 (0)
Please sign in to comment.