corelib/proc.rb in opal-0.4.4 vs corelib/proc.rb in opal-0.5.0
- old
+ new
@@ -1,19 +1,32 @@
class Proc
`def._isProc = true`
- `def.is_lambda = true`
+ `def.is_lambda = false`
def self.new(&block)
- `if (block === nil) { throw new Error("no block given"); }`
- `block.is_lambda = false`
+ unless block
+ raise ArgumentError, "tried to create a Proc object without a block"
+ end
+
block
end
- def call(*args)
+ def call(*args, &block)
%x{
- var result = #{self}.apply(null, #{args});
+ if (block !== nil) {
+ self._p = block;
+ }
+ var result;
+
+ if (self.is_lambda) {
+ result = self.apply(null, args);
+ }
+ else {
+ result = Opal.$yieldX(self, args);
+ }
+
if (result === $breaker) {
return $breaker.$v;
}
return result;
@@ -27,18 +40,17 @@
end
def lambda?
# This method should tell the user if the proc tricks are unavailable,
# (see Proc#lambda? on ruby docs to find out more).
- `!!#{self}.is_lambda`
+ `!!self.is_lambda`
end
+ # FIXME: this should support the various splats and optional arguments
def arity
- `#{self}.length - 1`
+ `self.length`
end
def to_n
self
end
end
-
-class Method < Proc; end