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: c7952014126a
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2f96455a49a9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Aug 26, 2015

  1. * Replicate #1077 with a spec (could not find any ruby specs for this)

    * If we're equal, return false right off the bat
    wied03 committed Aug 26, 2015
    Copy the full SHA
    35b2a09 View commit details
  2. Merge pull request #1078 from wied03/master

    Fix class descendant issue
    meh committed Aug 26, 2015
    Copy the full SHA
    2f96455 View commit details
Showing with 24 additions and 1 deletion.
  1. +6 −1 opal/corelib/module.rb
  2. +18 −0 spec/opal/core/language/class_spec.rb
7 changes: 6 additions & 1 deletion opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -30,9 +30,14 @@ def ===(object)
end

def <(other)
# class cannot be a descendant of itself
%x{
var working = self;
if (working === other) {
return false;
}
while (working) {
if (working === other) {
return true;
18 changes: 18 additions & 0 deletions spec/opal/core/language/class_spec.rb
Original file line number Diff line number Diff line change
@@ -20,3 +20,21 @@ def foo
ConstantWithAssignedClass.new.bar.should == :bar
end
end

describe "Class descendant check using < operator" do
klass1 = Class.new
klass2 = Class.new(klass1)
klass3 = Class.new

it "is a descendant" do
(klass2 < klass1).should == true
end

it "is not a descendant" do
(klass3 < klass1).should == false
end

it "is the same class" do
(klass1 < klass1).should == false
end
end