summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2015-07-02 00:42:00 -0600
committerDan Allen <dan.j.allen@gmail.com>2015-07-02 00:42:00 -0600
commit03a86cfc7ea2e80d89435e7dc22dbf33b9611d45 (patch)
tree045baf4a14ff893e1097c9732d275e22f9725287
parentefc006d8543961c5e0b982eeed7f123058ef91ff (diff)
parentdd4886ecc6dfa184c3f699acd35707e8fcbc1983 (diff)
Merge pull request #1386 from mojavelinux/issue-1385
resolves #1385 add implementation of != method to Opal
-rw-r--r--lib/asciidoctor/opal_ext/comparable.rb48
1 files changed, 33 insertions, 15 deletions
diff --git a/lib/asciidoctor/opal_ext/comparable.rb b/lib/asciidoctor/opal_ext/comparable.rb
index 7c3a85ee..98f39753 100644
--- a/lib/asciidoctor/opal_ext/comparable.rb
+++ b/lib/asciidoctor/opal_ext/comparable.rb
@@ -1,38 +1,56 @@
-# workaround for an infinite loop in Opal 0.6.2 when comparing numbers
+class BasicObject
+ # Provides implementation for missing != method BasicObject. Allows the
+ # method :!= to be sent to an object.
+ def != other
+ `self !== other`
+ end
+end
+
+# workaround for an infinite loop in Opal 0.6.x when comparing numbers
module Comparable
def == other
return true if equal? other
- return false unless cmp = (self <=> other)
- return `cmp == 0`
+ # if <=> returns nil, assume these objects can't be compared (and thus not equal)
+ return false unless res = (self <=> other)
+ return `res == 0`
rescue StandardError
false
end
+ def != other
+ return false if equal? other
+ # if <=> returns nil, assume these objects can't be compared (and thus not equal)
+ return true unless res = (self <=> other)
+ return `res != 0`
+ rescue StandardError
+ true
+ end
+
def > other
- unless cmp = (self <=> other)
- raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ unless res = (self <=> other)
+ raise ArgumentError, %(comparison of #{self.class} with #{other.class} failed)
end
- `cmp > 0`
+ `res > 0`
end
def >= other
- unless cmp = (self <=> other)
- raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ unless res = (self <=> other)
+ raise ArgumentError, %(comparison of #{self.class} with #{other.class} failed)
end
- `cmp >= 0`
+ `res >= 0`
end
def < other
- unless cmp = (self <=> other)
- raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ unless res = (self <=> other)
+ raise ArgumentError, %(comparison of #{self.class} with #{other.class} failed)
end
- `cmp < 0`
+ `res < 0`
end
def <= other
- unless cmp = (self <=> other)
- raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ unless res = (self <=> other)
+ raise ArgumentError, %(comparison of #{self.class} with #{other.class} failed)
end
- `cmp <= 0`
+ `res <= 0`
end
end