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: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 664f47ec7ac0
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b5ef3c6e251a
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 14, 2015

  1. Copy the full SHA
    ad51202 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    44fdce9 View commit details

Commits on Jul 16, 2015

  1. Merge pull request #1008 from vais/method-to_proc

    Method#to_proc returns a proc that is bound to the method's receiver
    vais committed Jul 16, 2015
    Copy the full SHA
    b5ef3c6 View commit details
Showing with 34 additions and 2 deletions.
  1. +5 −1 opal/corelib/method.rb
  2. +1 −1 opal/corelib/module.rb
  3. +28 −0 spec/opal/core/method/to_proc_spec.rb
6 changes: 5 additions & 1 deletion opal/corelib/method.rb
Original file line number Diff line number Diff line change
@@ -27,7 +27,11 @@ def unbind
end

def to_proc
@method
%x{
var proc = function () { return self.$call.apply(self, $slice.call(arguments)); };
proc.$$unbound = #@method;
return proc;
}
end

def inspect
2 changes: 1 addition & 1 deletion opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ def define_method(name, method = undefined, &block)
when Proc
method
when Method
method.to_proc
`#{method.to_proc}.$$unbound`
when UnboundMethod
lambda do |*args|
bound = method.bind(self)
28 changes: 28 additions & 0 deletions spec/opal/core/method/to_proc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe "Method#to_proc" do

it "returns a Proc object that is bound to the method's receiver" do
"hello".method(:capitalize).to_proc.call.should == "Hello"
"hello".method(:upcase).to_proc.call.should == "HELLO"
end

it "works with class methods" do
class Lender
def self.abc
self
end
def self.xyz
abc
end
end

module Namespace
class Borrower
class << self
define_method(:xyz, &::Lender.method(:xyz))
end
end
end

Namespace::Borrower.xyz.should == Lender
end
end