Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f1f0d7577fe4
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0ec240abd1a8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 25, 2015

  1. Added mirror for Proc#curry. Improves #3406.

    There is still a lot of cruft in the Rubinius kernel but generally we use the
    mirror facility to implement methods that are not public Ruby API methods (and are
    generally C functions in MRI).
    brixen committed May 25, 2015
    Copy the full SHA
    93a80e0 View commit details
  2. Copy the full SHA
    0ec240a View commit details
Showing with 27 additions and 27 deletions.
  1. +1 −0 kernel/common/load_order.txt
  2. +6 −27 kernel/common/proc.rb
  3. +20 −0 kernel/common/proc_mirror.rb
1 change: 1 addition & 0 deletions kernel/common/load_order.txt
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ autoload.rbc
module.rbc
binding.rbc
proc.rbc
proc_mirror.rbc
enumerable_helper.rbc
enumerable.rbc
enumerator.rbc
33 changes: 6 additions & 27 deletions kernel/common/proc.rb
Original file line number Diff line number Diff line change
@@ -14,23 +14,6 @@ def self.__from_block__(env)
end
end

def self.__make_curry_proc__(proc, passed, arity)
is_lambda = proc.lambda?
passed.freeze

__send__((is_lambda ? :lambda : :proc)) do |*argv, &passed_proc|
my_passed = passed + argv
if my_passed.length < arity
if !passed_proc.nil?
warn "#{caller[0]}: given block not used"
end
__make_curry_proc__(proc, my_passed, arity)
else
proc.call(*my_passed)
end
end
end

def self.new(*args)
env = nil

@@ -111,19 +94,15 @@ def curry(curried_arity = nil)

args = []

f = Proc.__make_curry_proc__(self, [], arity)
m = Rubinius::Mirror.reflect self
f = m.curry self, [], arity

f.singleton_class.send(:define_method, :binding) {
f.singleton_class.send(:define_method, :binding) do
raise ArgumentError, "cannot create binding from f proc"
}

f.singleton_class.send(:define_method, :parameters) {
[[:rest]]
}
end

f.singleton_class.send(:define_method, :source_location) {
nil
}
f.singleton_class.thunk_method :parameters, [[:rest]]
f.singleton_class.thunk_method :source_location, nil

f
end
20 changes: 20 additions & 0 deletions kernel/common/proc_mirror.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Rubinius
class Mirror
class Proc < Mirror
def curry(executable, args, arity)
args.freeze

name = executable.lambda? ? :lambda : :proc

Proc.__send__(name) do |*a, &b|
all_args = args + a
if all_args.size < arity
curry executable, all_args, arity
else
executable[*all_args]
end
end
end
end
end
end