// Generated by CoffeeScript 1.3.3 /* RubyJS Alpha 0.7.2 Copyright (c) 2012 Sebastian Burkhard All rights reserved. http://www.rubyjs.org/LICENSE.txt */ (function() { var $args, $args$single, $block$args, $block$multi, $block$single, $blockCallback, $exec, $execute, CharTable, Coerce, CoerceProto, RStrProto, method, name, nativeArray, nativeNumber, nativeObject, nativeRegExp, nativeString, previousR, root, toString, _ref, _slice_, _toString_, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; root = typeof global !== "undefined" && global !== null ? global : window; root.RubyJS = function(obj, recursive, block) { return RubyJS.Base.prototype.box(obj, recursive, block); }; RubyJS.VERSION = '0.7.2'; if (root.R != null) { previousR = root.R; } RubyJS.noConflict = function() { root.R = previousR; return RubyJS; }; root.R = RubyJS; nativeArray = Array; nativeNumber = Number; nativeObject = Object; nativeRegExp = RegExp; nativeString = String; _toString_ = Object.prototype.toString; _slice_ = Array.prototype.slice; RubyJS.extend = function(obj, mixin) { var method, name; for (name in mixin) { method = mixin[name]; obj[name] = method; } return obj; }; if (typeof exports !== 'undefined') { exports.R = R; exports.RubyJS = RubyJS; } toString = Object.prototype.toString; RubyJS.Kernel = (function() { function Kernel() {} Kernel.prototype.rubyjs = function() { return true; }; Kernel.prototype.box = function(obj, recursive, block) { if (obj == null) return obj;; var object_type, _v; if (typeof obj === 'object') { if (obj.rubyjs != null) { return obj; } _v = obj.valueOf(); if (typeof _v !== 'object') { obj = _v; } else { if (R.Array.isNativeArray(obj)) { object_type = '[object Array]'; } else { object_type = _toString_.call(obj); } } } if (typeof obj === 'number') { obj = RubyJS.Numeric.typecast(obj); } else if (typeof obj === 'string') { obj = new R.String(obj); } else if (object_type === '[object Array]') { obj = new R.Array(obj, recursive === true); } else if (object_type === '[object RegExp]') { obj = R.Regexp.try_convert(obj); } if (typeof recursive === 'function') { block = recursive; recursive = false; } if (typeof block === 'function') { obj = block.call(obj); if (obj === null || obj === void 0) { obj = null; } else if (obj.to_native != null) { obj = obj.to_native(true); } } return obj; }; Kernel.prototype.w = function(str) { return R(str).split(/\s+/); }; Kernel.prototype.r = function(a, b, excluding) { if (excluding === true) { return R.Range["new"](a, b, true); } else { return R.Range["new"](a, b); } }; Kernel.prototype.f = function(flt) { return new R.Float(flt); }; Kernel.prototype.rng = Kernel.prototype.r; Kernel.prototype.l = function(obj, recursive) { if (recursive == null) { recursive = false; } if (typeof obj === 'object') { if (obj.to_native != null) { return obj.to_native(true); } else { return obj; } } else { return obj; } }; Kernel.prototype.catch_break = function(block, context) { var breaker; if (context == null) { context = this; } breaker = new R.Breaker(); try { return block.call(context, breaker); } catch (e) { return breaker.handle_break(e); } }; Kernel.prototype.$Array = function(obj, recursive) { var e; if (recursive == null) { recursive = false; } if (recursive === true) { return RubyJS.Array["new"]((function() { var _i, _len, _results; _results = []; for (_i = 0, _len = obj.length; _i < _len; _i++) { e = obj[_i]; _results.push(this.box(e)); } return _results; }).call(this)); } else { return RubyJS.Array["new"](obj); } }; Kernel.prototype.$Array_r = function(obj) { return this.$Array(obj, true); }; Kernel.prototype.$Float = function(obj) { var stripped; obj = this.box(obj); if (obj === null) { throw RubyJS.TypeError["new"](); } if (obj.to_f == null) { throw RubyJS.TypeError["new"](); } if (obj.is_float != null) { return obj; } else if (obj.is_string != null) { stripped = obj.strip(); if (stripped.valid_float()) { return new RubyJS.Float(+stripped.unbox().replace(/_/g, '')); } else { throw RubyJS.ArgumentError["new"](); } } else if (obj.rubyjs != null) { return new RubyJS.Float(obj.unbox()); } else { return new RubyJS.Float(obj); } }; Kernel.prototype.$Integer = function(obj) { var stripped; obj = this.box(obj); if (obj === null || obj === void 0) { throw RubyJS.TypeError["new"](); } if (obj.is_integer != null) { return obj; } else if (obj.is_string != null) { stripped = obj.strip(); if (stripped.valid_float()) { return new RubyJS.Fixnum(Math.floor(+stripped.unbox().replace(/_/g, ''))); } else { throw RubyJS.ArgumentError["new"](); } } else if (obj.rubyjs != null) { return new RubyJS.Fixnum(Math.floor(obj.unbox())); } else { return new RubyJS.Fixnum(Math.floor(obj)); } }; Kernel.prototype.$Integer = Kernel.prototype.$Integer; Kernel.prototype.$String = function(obj) { return RubyJS.String.try_convert(obj) || (function() { throw RubyJS.TypeError["new"](); })(); }; Kernel.prototype.$Range = function(start, end, exclusive) { return RubyJS.Range["new"](start, end, exclusive); }; Kernel.prototype.puts = function(obj) { return console.log(obj); }; Kernel.prototype.rand = function(limit) { var r; r = R(Math.random()); if (limit) { return r.multiply(limit).to_i(); } else { return r; } }; return Kernel; })(); Coerce = (function() { function Coerce() {} Coerce.prototype.single_block_args = function(args, block) { if (block) { if (block.length !== 1) { if (args.length > 1) { return _slice_.call(args); } else { return args[0]; } } else { return args[0]; } } else { if (args.length !== 1) { return _slice_.call(args); } else { return args[0]; } } }; Coerce.prototype.coerce = function(obj, to_what, skip_native) { if (skip_native !== void 0 && skip_native === typeof obj) { return obj; } else { if (obj === null || obj === void 0) { throw new R.TypeError["new"](); } obj = R(obj); if (obj[to_what] == null) { throw RubyJS.TypeError["new"]("TypeError: cant't convert ... into String"); } if (skip_native !== void 0) { return obj[to_what]().to_native(); } else { return obj[to_what](); } } }; Coerce.prototype.to_num_native = function(obj) { if (typeof obj === 'number') { return obj; } else { obj = R(obj); if (!(obj.is_numeric != null)) { throw RubyJS.TypeError["new"](); } return obj.to_native(); } }; Coerce.prototype.to_int = function(obj) { return this.coerce(obj, 'to_int'); }; Coerce.prototype.to_int_native = function(obj) { if (typeof obj === 'number' && (obj % 1 === 0)) { return obj; } else { return this.coerce(obj, 'to_int').to_native(); } }; Coerce.prototype.to_str = function(obj) { return this.coerce(obj, 'to_str'); }; Coerce.prototype.to_str_native = function(obj) { return this.coerce(obj, 'to_str', 'string'); }; Coerce.prototype.to_ary = function(obj) { return this.coerce(obj, 'to_ary'); }; return Coerce; })(); CoerceProto = Coerce.prototype; R.CoerceProto = Coerce.prototype; RubyJS.Object = (function() { function Object() {} Object.include = function(mixin, replace) { var method, name, _ref; if (replace == null) { replace = false; } _ref = mixin.prototype; for (name in _ref) { method = _ref[name]; if (replace) { this.prototype[name] = method; } else { if (!this.prototype[name]) { this.prototype[name] = method; } } } return mixin; }; Object.__add_default_aliases__ = function(proto) { if (proto['<<'] != null) { proto.append = proto['<<']; } if (proto['=='] != null) { proto.equals = proto['==']; } if (proto['==='] != null) { proto.equal_case = proto['===']; } if (proto['<=>'] != null) { proto.cmp = proto['<=>']; } if (proto['%'] != null) { proto.modulo = proto['%']; } if (proto['+'] != null) { proto.plus = proto['+']; } if (proto['-'] != null) { proto.minus = proto['-']; } if (proto['*'] != null) { proto.multiply = proto['*']; } if (proto['**'] != null) { proto.exp = proto['**']; } if (proto['/'] != null) { proto.divide = proto['/']; } if (proto.equal_case != null) { proto.equalCase = proto.equal_case; } if (proto.equal_value != null) { proto.equalValue = proto.equal_value; } if (proto.to_a != null) { proto.toA = proto.to_a; } if (proto.to_f != null) { proto.toF = proto.to_f; } if (proto.to_i != null) { proto.toI = proto.to_i; } if (proto.to_int != null) { proto.toInt = proto.to_int; } if (proto.to_s != null) { proto.toS = proto.to_s; } if (proto.to_str != null) { proto.toStr = proto.to_str; } if (proto.to_enum != null) { proto.toEnum = proto.to_enum; } if (proto.to_native != null) { return proto.toNative = proto.to_native; } }; Object.include(RubyJS.Kernel); Object.prototype.__ensure_args_length = function(args, length) { if (args.length !== length) { throw RubyJS.ArgumentError["new"](); } }; Object.prototype.__ensure_numeric = function(obj) { if ((obj != null ? obj.is_numeric : void 0) == null) { throw RubyJS.TypeError["new"](); } }; Object.prototype.__ensure_string = function(obj) { if ((obj != null ? obj.is_string : void 0) == null) { throw RubyJS.TypeError["new"](); } }; Object.prototype.__extract_block = function(args) { var idx, _ref; idx = args.length; while (--idx >= 0) { if (((_ref = args[idx]) != null ? _ref.call : void 0) != null) { return args.pop(); } } return null; }; Object.prototype.send = function() { var args, method_name; method_name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return this[method_name](args); }; Object.prototype.respond_to = function(method_name) { return this[method_name] != null; }; Object.prototype.to_enum = function() { var args, iter; iter = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (iter == null) { iter = "each"; } return new RubyJS.Enumerator(this, iter, args); }; Object.prototype.tap = function(block) { block(this); return this; }; return Object; })(); RubyJS.Breaker = (function() { function Breaker(return_value, broken) { this.return_value = return_value != null ? return_value : null; this.broken = broken != null ? broken : false; } Breaker.prototype["break"] = function(return_value) { this.broken = true; this.return_value = return_value; throw this; }; Breaker.prototype.handle_break = function(e) { if (this === e) { return e.return_value; } else { throw e; } }; return Breaker; })(); RubyJS.Base = (function(_super) { __extends(Base, _super); function Base() { return Base.__super__.constructor.apply(this, arguments); } Base.include(RubyJS.Kernel); Base.prototype['$~'] = null; Base.prototype['$,'] = null; Base.prototype['$;'] = "\n"; Base.prototype['$/'] = "\n"; Base.prototype.inspect = function(obj) { if (obj === null || obj === 'undefined') { return 'null'; } else if (obj.inspect != null) { return obj.inspect(); } else if (RubyJS.Array.isNativeArray(obj)) { return "[" + obj + "]"; } else { return obj; } }; Base.prototype.pollute_global = function() { var args, method, _i, _len; if (arguments.length === 0) { args = ['proc', 'puts', 'truthy', 'falsey', 'inspect']; } else { args = arguments; } for (_i = 0, _len = args.length; _i < _len; _i++) { method = args[_i]; if (root[method] != null) { R.puts("pollute_global(): " + method + " already exists."); } else { root[method] = this[method]; } } return null; }; Base.prototype.proc = function() { var args, key; key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (args.length === 0) { return function(el) { return el[key](); }; } else { return function(el) { return el[key].apply(el, args); }; } }; Base.prototype.falsey = function(obj) { return obj === false || obj === null || obj === void 0; }; Base.prototype.truthy = function(obj) { return !this.falsey(obj); }; Base.prototype.unbox = function(obj, recursive) { if (recursive == null) { recursive = false; } return obj.unbox(recursive); }; Base.prototype.respond_to = function(obj, function_name) { return obj[function_name] !== void 0; }; Base.prototype.extend = function(obj, mixin) { var method, name; for (name in mixin) { method = mixin[name]; obj[name] = method; } return obj; }; return Base; })(RubyJS.Object); _ref = RubyJS.Base.prototype; for (name in _ref) { method = _ref[name]; RubyJS[name] = method; } RubyJS.ArgumentError = (function(_super) { __extends(ArgumentError, _super); function ArgumentError() { return ArgumentError.__super__.constructor.apply(this, arguments); } ArgumentError["new"] = function() { return new RubyJS.ArgumentError('ArgumentError'); }; return ArgumentError; })(Error); RubyJS.RegexpError = (function(_super) { __extends(RegexpError, _super); function RegexpError() { return RegexpError.__super__.constructor.apply(this, arguments); } RegexpError["new"] = function() { return new RubyJS.RegexpError('RegexpError'); }; return RegexpError; })(Error); RubyJS.TypeError = (function(_super) { __extends(TypeError, _super); function TypeError() { return TypeError.__super__.constructor.apply(this, arguments); } TypeError["new"] = function() { return new RubyJS.TypeError('TypeError'); }; return TypeError; })(Error); RubyJS.IndexError = (function(_super) { __extends(IndexError, _super); function IndexError() { return IndexError.__super__.constructor.apply(this, arguments); } IndexError["new"] = function() { return new RubyJS.IndexError('IndexError'); }; return IndexError; })(Error); RubyJS.FloatDomainError = (function(_super) { __extends(FloatDomainError, _super); function FloatDomainError() { return FloatDomainError.__super__.constructor.apply(this, arguments); } FloatDomainError["new"] = function() { return new RubyJS.FloatDomainError('FloatDomainError'); }; return FloatDomainError; })(Error); RubyJS.RangeError = (function(_super) { __extends(RangeError, _super); function RangeError() { return RangeError.__super__.constructor.apply(this, arguments); } RangeError["new"] = function() { return new RubyJS.RangeError('RangeError'); }; return RangeError; })(Error); RubyJS.StandardError = (function(_super) { __extends(StandardError, _super); function StandardError() { return StandardError.__super__.constructor.apply(this, arguments); } StandardError["new"] = function() { return new RubyJS.StandardError('StandardError'); }; return StandardError; })(Error); RubyJS.ZeroDivisionError = (function(_super) { __extends(ZeroDivisionError, _super); function ZeroDivisionError() { return ZeroDivisionError.__super__.constructor.apply(this, arguments); } ZeroDivisionError["new"] = function() { return new RubyJS.ZeroDivisionError('ZeroDivisionError'); }; return ZeroDivisionError; })(Error); RubyJS.NotSupportedError = (function(_super) { __extends(NotSupportedError, _super); function NotSupportedError() { return NotSupportedError.__super__.constructor.apply(this, arguments); } NotSupportedError["new"] = function() { return new RubyJS.NotSupportedError('NotSupportedError'); }; return NotSupportedError; })(Error); RubyJS.NotImplementedError = (function(_super) { __extends(NotImplementedError, _super); function NotImplementedError() { return NotImplementedError.__super__.constructor.apply(this, arguments); } NotImplementedError["new"] = function() { return new RubyJS.NotImplementedError('NotImplementedError'); }; return NotImplementedError; })(Error); RubyJS.Comparable = (function() { function Comparable() {} Comparable.prototype['<'] = function(other) { var cmp; cmp = this['<=>'](other); if (cmp === null) { throw RubyJS.TypeError["new"](); } return cmp < 0; }; Comparable.prototype['>'] = function(other) { var cmp; cmp = this['<=>'](other); if (cmp === null) { throw RubyJS.TypeError["new"](); } return cmp > 0; }; Comparable.prototype['<='] = function(other) { var cmp; cmp = this['<=>'](other); if (cmp === null) { throw RubyJS.TypeError["new"](); } return cmp <= 0; }; Comparable.prototype['>='] = function(other) { var cmp; cmp = this['<=>'](other); if (cmp === null) { throw RubyJS.TypeError["new"](); } return cmp >= 0; }; Comparable.prototype.between = function(min, max) { return this['>='](min) && this['<='](max); }; Comparable.cmp = function(a, b) { if (typeof a !== 'object' && typeof a === typeof b) { if (a === b) { return 0; } else { if (a < b) { return -1; } else { return 1; } } } else { a = R(a); if (a['<=>'] == null) { throw 'NoMethodError'; } return a['<=>'](b); } }; Comparable.cmpstrict = function(a, b) { var cmp; if (typeof a === typeof b && typeof a !== 'object') { if (a === b) { return 0; } else { if (a < b) { return -1; } else { return 1; } } } else { a = R(a); if (a['<=>'] == null) { throw 'NoMethodError'; } cmp = a['<=>'](b); if (cmp === null) { throw R.ArgumentError["new"](); } return cmp; } }; Comparable.prototype.cmp = Comparable.prototype['<=>']; Comparable.prototype.lt = Comparable.prototype['<']; Comparable.prototype.lteq = Comparable.prototype['<=']; Comparable.prototype.gt = Comparable.prototype['>']; Comparable.prototype.gteq = Comparable.prototype['>=']; return Comparable; })(); $args = CoerceProto.single_block_args; $exec = function(cntxt, block, _arguments) { if (block.length > 1 && (R.Array.isNativeArray(_arguments))) { return block.apply(cntxt, _arguments); } else { return block.call(cntxt, _arguments); } }; $execute = function(cntxt, block, _arguments) { var args; args = $args(_arguments, block); if (block.length !== 1 && R.Array.isNativeArray(args)) { return block.apply(cntxt, args); } else { return block.call(cntxt, args); } }; $blockCallback = function(thisArg, block) { if (block && (block.call != null)) { if (block.length !== 1) { return $block$multi; } else { return $block$single; } } else { return $block$args; } }; $args$single = function(args) { if (args.length !== 1) { return _slice_.call(args); } else { return args[0]; } }; $block$args = function(thisArg, block, args) { return CoerceProto.single_block_args(args, block); }; $block$multi = function(thisArg, block, args) { args = args.length > 1 ? _slice_.call(args) : args[0]; if (R.Array.isNativeArray(args)) { return block.apply(thisArg, args); } else { return block.call(thisArg, args); } }; $block$single = function(thisArg, block, _arguments) { var args; args = _arguments[0]; return block.call(thisArg, args); }; RubyJS.Enumerable = (function() { function Enumerable() {} Enumerable.prototype.is_enumerable = function() { return true; }; Enumerable.prototype.all = function(block) { return this.catch_break(function(breaker) { var callback; callback = $blockCallback(this, block); this.each(function() { var result; result = callback(this, block, arguments); if (R.falsey(result)) { return breaker["break"](false); } }); return true; }); }; Enumerable.prototype['all?'] = Enumerable.prototype.all; Enumerable.prototype.any = function(block) { return this.catch_break(function(breaker) { var callback; callback = $blockCallback(this, block); this.each(function(args) { var result; result = callback(this, block, arguments); if (!R.falsey(result)) { return breaker["break"](true); } }); return false; }); }; Enumerable.prototype['any?'] = Enumerable.prototype.any; Enumerable.prototype.collect_concat = function(block) { var ary, callback; if (block == null) { block = null; } if (!(block && (block.call != null))) { return this.to_enum('collect_concat'); } callback = $blockCallback(this, block); ary = []; this.each(function() { return ary.push(callback(this, block, arguments)); }); return new R.Array(ary).flatten(1); }; Enumerable.prototype.flat_map = Enumerable.prototype.collect_concat; Enumerable.prototype.count = function(block) { var callback, counter; counter = 0; if (block === void 0) { this.each(function() { return counter += 1; }); } else if (block === null) { this.each(function(el) { if (el === null) { return counter += 1; } }); } else if (block.call != null) { callback = $blockCallback(this, block); this.each(function() { var result; result = callback(this, block, arguments); if (!R.falsey(result)) { return counter += 1; } }); } else { this.each(function(el) { if (R(el)['=='](block)) { return counter += 1; } }); } return this.$Integer(counter); }; Enumerable.prototype.cycle = function(n, block) { var cache, callback, i, many, _results, _results1; if (arguments.length > 2) { throw R.ArgumentError["new"](); } if (!block) { if (n && (n.call != null)) { block = n; n = null; } } if (!(n === null || n === void 0)) { many = CoerceProto.to_int_native(n); if (many <= 0) { return null; } } else { many = null; } if (!block) { return this.to_enum('cycle', n); } callback = $blockCallback(this, block); cache = new R.Array([]); this.each(function() { var args; args = $args(arguments, block); cache.append(args); return callback(this, block, arguments); }); if (cache.empty()) { return null; } if (many > 0) { i = 0; many -= 1; _results = []; while (many > i) { _results.push(cache.each(function() { callback(this, block, arguments); return i += 1; })); } return _results; } else { _results1 = []; while (true) { _results1.push(cache.each(function() { return callback(this, block, arguments); })); } return _results1; } }; Enumerable.prototype.drop = function(n) { var ary; this.__ensure_args_length(arguments, 1); n = CoerceProto.to_int_native(n); if (n < 0) { throw R.ArgumentError["new"](); } ary = []; this.each_with_index(function(el, idx) { if (n <= idx) { return ary.push(el); } }); return new R.Array(ary); }; Enumerable.prototype.drop_while = function(block) { var ary, callback, dropping; if (!(block && (block.call != null))) { return this.to_enum('drop_while'); } callback = $blockCallback(this, block); ary = []; dropping = true; this.each(function() { var args; if (!(dropping && callback(this, block, arguments))) { dropping = false; args = $args(arguments); return ary.push(args); } }); return new R.Array(ary); }; Enumerable.prototype.each_cons = function() { var args, ary, block, n; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); if (!(block && (block.call != null))) { return this.to_enum.apply(this, ['each_cons'].concat(__slice.call(args))); } this.__ensure_args_length(args, 1); n = CoerceProto.to_int_native(args[0]); if (!(n > 0)) { throw R.ArgumentError["new"](); } ary = []; this.each(function() { ary.push($args(arguments)); if (ary.length > n) { ary.shift(); } if (ary.length === n) { return $exec(this, block, ary.slice(0)); } }); return null; }; Enumerable.prototype.each_entry = function(block) { if (arguments.length > 1) { throw R.ArgumentError["new"](); } if (!(block && (block.call != null))) { return this.to_enum('each_entry'); } this.each(function() { var args; args = $args(arguments); return $exec(this, block, args); }); return this; }; Enumerable.prototype.each_slice = function(n, block) { var ary; if (!n) { throw R.ArgumentError["new"](); } n = CoerceProto.to_int_native(n); if (n <= 0) { throw R.ArgumentError["new"](); } if (block && !(block.call != null)) { throw R.ArgumentError["new"](); } if (block === void 0) { return this.to_enum('each_slice', n); } ary = []; this.each(function() { ary.push($args(arguments)); if (ary.length === n) { $exec(this, block, ary.slice(0)); return ary = []; } }); if (ary.length !== 0) { $exec(this, block, ary.slice(0)); } return null; }; Enumerable.prototype.each_with_index = function(block) { var idx; if (!(block && (block.call != null))) { return this.to_enum('each_with_index'); } idx = 0; this.each(function() { var val; val = block.call(this, $args(arguments), idx); idx += 1; return val; }); return this; }; Enumerable.prototype.each_with_object = function(obj, block) { if (!(block && (block.call != null))) { return this.to_enum('each_with_object', obj); } this.each(function() { return block.apply(this, [$args(arguments), obj]); }); return obj; }; Enumerable.prototype.find = function(ifnone, block) { var callback; if (block == null) { block = null; } if (block === null) { block = ifnone; ifnone = null; } callback = $blockCallback(this, block); return this.catch_break(function(breaker) { this.each(function() { if (!R.falsey(callback(this, block, arguments))) { return breaker["break"]($args(arguments)); } }); return typeof ifnone === "function" ? ifnone() : void 0; }); }; Enumerable.prototype.detect = Enumerable.prototype.find; Enumerable.prototype.find_all = function(block) { var ary, callback; if (!(block && (block.call != null))) { return this.to_enum('find_all'); } ary = []; callback = $blockCallback(this, block); this.each(function() { if (!R.falsey(callback(this, block, arguments))) { return ary.push($args(arguments)); } }); return new R.Array(ary); }; Enumerable.prototype.select = Enumerable.prototype.find_all; Enumerable.prototype.find_index = function(value) { var block, callback, idx; if (arguments.length === 0) { return this.to_enum('find_index'); } value = R(value); if (value.call != null) { block = value; } else { block = function(el) { return R(el)['=='](value) || el === value; }; } idx = 0; callback = $blockCallback(this, block); return this.catch_break(function(breaker) { this.each(function() { if (callback(this, block, arguments)) { breaker["break"](new R.Fixnum(idx)); } return idx += 1; }); return null; }); }; Enumerable.prototype.first = function(n) { if (n == null) { n = null; } if (n !== null) { n = CoerceProto.to_int_native(n); if (n < 0) { throw new RubyJS.ArgumentError('ArgumentError'); } return this.take(n); } else { return this.take(1).to_native()[0]; } }; Enumerable.prototype.include = function(other) { other = this.box(other); return this.catch_break(function(breaker) { this.each(function(el) { el = R(el); if ((typeof el['=='] === "function" ? el['=='](other) : void 0) || (typeof other['=='] === "function" ? other['=='](el) : void 0) || el === other) { return breaker["break"](true); } }); return false; }); }; Enumerable.prototype.__inject_args__ = function(initial, sym, block) { var _method, _ref1; if ((sym != null ? sym.call : void 0) != null) { block = sym; } else if (sym) { block = function(memo, el) { return memo[sym](el); }; } else if (((_ref1 = this.box(initial)) != null ? _ref1.is_string : void 0) != null) { _method = "" + initial; block = function(memo, el) { return memo[_method](el); }; initial = void 0; } else if (initial.call != null) { block = initial; initial = void 0; } return [initial, sym, block]; }; Enumerable.prototype.inject = function(init, sym, block) { var _ref1; _ref1 = this.__inject_args__(init, sym, block), init = _ref1[0], sym = _ref1[1], block = _ref1[2]; this.each(function() { var args; if (init === void 0) { return init = $args(arguments); } else { args = arguments; args = args.length !== 1 ? _slice_.call(args) : args[0]; return init = block.call(this, init, args); } }); return init; }; Enumerable.prototype.iterator = function() { return this.each(); }; Enumerable.prototype.grep = function(pattern, block) { var ary; ary = new R.Array([]); pattern = R(pattern); if (block) { this.each(function(el) { if (pattern['==='](el)) { return ary.append($execute(this, block, arguments)); } }); } else { this.each(function(el) { if (pattern['==='](el)) { return ary.append(el); } }); } return ary; }; Enumerable.prototype.group_by = function(block) { var h; if ((block != null ? block.call : void 0) == null) { return this.to_enum('group_by'); } h = {}; this.each(function() { var args, key; args = $args(arguments, block); key = $execute(this, block, arguments); h[key] || (h[key] = new R.Array([])); return h[key].append(args); }); return h; }; Enumerable.prototype.map = function(block) { var arr; if ((block != null ? block.call : void 0) == null) { return this.to_enum('map'); } arr = []; if (block.length !== 1) { this.each(function() { return arr.push($execute(this, block, arguments)); }); } else { this.each(function(el) { return arr.push(block.apply(this, arguments)); }); } return new R.Array(arr, false); }; Enumerable.prototype.collect = Enumerable.prototype.map; Enumerable.prototype.member = Enumerable.prototype.include; Enumerable.prototype.max = function(block) { var arr, max, _max; max = void 0; block || (block = RubyJS.Comparable.cmp); if (typeof this.__samesame__ === "function" ? this.__samesame__() : void 0) { arr = this.__native__; if (arr.length < 65535) { _max = Math.max.apply(Math, arr); if (_max !== NaN) { return _max; } } } this.each(function(item) { var comp; if (max === void 0) { return max = item; } else { comp = block(item, max); if (comp === null) { throw R.ArgumentError["new"](); } if (comp > 0) { return max = item; } } }); return max || null; }; Enumerable.prototype.max_by = function(block) { var max; if ((block != null ? block.call : void 0) == null) { return this.to_enum('max_by'); } max = void 0; this.each(function(item) { var cmp; if (max === void 0) { return max = item; } else { cmp = R.Comparable.cmpstrict(block(item), block(max)); if (cmp > 0) { return max = item; } } }); return max || null; }; Enumerable.prototype.min = function(block) { var arr, min, _min; min = void 0; block || (block = RubyJS.Comparable.cmp); if (typeof this.__samesame__ === "function" ? this.__samesame__() : void 0) { arr = this.__native__; if (arr.length < 65535) { _min = Math.min.apply(Math, arr); if (_min !== NaN) { return _min; } } } this.each(function(item) { var comp; if (min === void 0) { return min = item; } else { comp = block.call(this, item, min); if (comp === null) { throw R.ArgumentError["new"](); } if (comp < 0) { return min = item; } } }); return min || null; }; Enumerable.prototype.min_by = function(block) { var min; if ((block != null ? block.call : void 0) == null) { return this.to_enum('min_by'); } min = void 0; this.each(function(item) { var cmp; if (min === void 0) { return min = item; } else { cmp = R.Comparable.cmpstrict(block(item), block(min)); if (cmp < 0) { return min = item; } } }); return min || null; }; Enumerable.prototype.minmax = function(block) { return R([this.min(block), this.max(block)]); }; Enumerable.prototype.minmax_by = function(block) { if ((block != null ? block.call : void 0) == null) { return this.to_enum('minmax_by'); } return R([this.min_by(block), this.max_by(block)]); }; Enumerable.prototype.none = function(block) { return this.catch_break(function(breaker) { var callback; callback = $blockCallback(this, block); this.each(function(args) { var result; result = callback(this, block, arguments); if (!R.falsey(result)) { return breaker["break"](false); } }); return true; }); }; Enumerable.prototype['none?'] = Enumerable.prototype.none; Enumerable.prototype.one = function(block) { var counter; counter = 0; return this.catch_break(function(breaker) { var callback; callback = $blockCallback(this, block); this.each(function(args) { var result; result = callback(this, block, arguments); if (!R.falsey(result)) { counter += 1; } if (counter > 1) { return breaker["break"](false); } }); return counter === 1; }); }; Enumerable.prototype['one?'] = Enumerable.prototype.one; Enumerable.prototype.partition = function(block) { var left, right; if (!(block && (block.call != null))) { return this.to_enum('partition'); } left = []; right = []; this.each(function() { var args; args = $args(arguments); if ($exec(this, block, args)) { return left.push(args); } else { return right.push(args); } }); return new R.Array([new R.Array(left), new R.Array(right)]); }; Enumerable.prototype.reduce = Enumerable.prototype.inject; Enumerable.prototype.reject = function(block) { var ary; if (!(block && (block.call != null))) { return this.to_enum('reject'); } ary = []; this.each(function() { if (R.falsey($execute(this, block, arguments))) { return ary.push($args(arguments)); } }); return new R.Array(ary); }; Enumerable.prototype.reverse_each = function(block) { if (!(block && (block.call != null))) { return this.to_enum('reverse_each'); } this.to_a().reverse_each(block); return this; }; Enumerable.prototype.slice_before = function() { var arg, args, block, has_init, self; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); arg = R(args[0]); if (block) { has_init = !(arg === void 0); } else { block = function(elem) { return arg['==='](elem); }; } self = this; return R.Enumerator.create(function(yielder) { var accumulator; accumulator = null; self.each(function(elem) { var start_new; start_new = has_init ? block(elem, arg.dup()) : block(elem); if (start_new) { if (accumulator) { yielder["yield"](accumulator); } return accumulator = R([elem]); } else { accumulator || (accumulator = new R.Array([])); return accumulator.append(elem); } }); if (accumulator) { return yielder["yield"](accumulator); } }); }; Enumerable.prototype.sort = function(block) { var arr; block || (block = R.Comparable.cmpstrict); arr = this.to_a().to_native().sort(block); return new R.Array(arr); }; Enumerable.prototype.sort_by = function(block) { var ary; if (!(block && (block.call != null))) { return this.to_enum('sort_by'); } ary = []; this.each(function(value) { return ary.push(new R.Enumerable.SortedElement(value, $execute(this, block, arguments))); }); ary = new R.Array(ary); return ary.sort().map(function(se) { return se.value; }); }; Enumerable.prototype.take = function(n) { var arr; this.__ensure_args_length(arguments, 1); n = CoerceProto.to_int_native(n); if (n < 0) { throw R.ArgumentError["new"](); } arr = []; this.catch_break(function(breaker) { return this.each(function() { if (arr.length === n) { breaker["break"](); } return arr.push($args(arguments)); }); }); return new R.Array(arr); }; Enumerable.prototype.take_while = function(block) { var ary; if (!(block && (block.call != null))) { return this.to_enum('take_while'); } ary = []; this.catch_break(function(breaker) { return this.each(function() { if (R.falsey(block.apply(this, arguments))) { breaker["break"](); } return ary.push($args(arguments)); }); }); return new R.Array(ary); }; Enumerable.prototype.to_a = function() { var ary; ary = []; this.each(function() { ary.push($args(arguments)); return null; }); return new RubyJS.Array(ary); }; Enumerable.prototype.to_enum = function() { var args, iter; iter = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (iter == null) { iter = "each"; } return new RubyJS.Enumerator(this, iter, args); }; Enumerable.prototype.entries = Enumerable.prototype.to_a; Enumerable.prototype.zip = function() { var block, idx, others, results; others = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(others); others = R(others).map(function(other) { var o; o = R(other); if (o.to_ary != null) { return o.to_ary(); } else { return o.to_enum('each'); } }); results = new R.Array([]); idx = 0; this.each(function(el) { var inner; inner = R([el]); others.each(function(other) { el = other.is_array != null ? other.at(idx) : other.next(); if (el === void 0) { el = null; } return inner.append(el); }); if (block) { block(inner); } results.append(inner); return idx += 1; }); if (block) { return null; } else { return results; } }; Enumerable.prototype.collectConcat = Enumerable.prototype.collect_concat; Enumerable.prototype.dropWhile = Enumerable.prototype.drop_while; Enumerable.prototype.eachCons = Enumerable.prototype.each_cons; Enumerable.prototype.eachEntry = Enumerable.prototype.each_entry; Enumerable.prototype.eachSlice = Enumerable.prototype.each_slice; Enumerable.prototype.eachWithIndex = Enumerable.prototype.each_with_index; Enumerable.prototype.eachWithObject = Enumerable.prototype.each_with_object; Enumerable.prototype.findAll = Enumerable.prototype.find_all; Enumerable.prototype.findIndex = Enumerable.prototype.find_index; Enumerable.prototype.flatMap = Enumerable.prototype.flat_map; Enumerable.prototype.groupBy = Enumerable.prototype.group_by; Enumerable.prototype.maxBy = Enumerable.prototype.max_by; Enumerable.prototype.minBy = Enumerable.prototype.min_by; Enumerable.prototype.minmaxBy = Enumerable.prototype.minmax_by; Enumerable.prototype.reverseEach = Enumerable.prototype.reverse_each; Enumerable.prototype.sliceBefore = Enumerable.prototype.slice_before; Enumerable.prototype.sortBy = Enumerable.prototype.sort_by; Enumerable.prototype.takeWhile = Enumerable.prototype.take_while; Enumerable.prototype.toA = Enumerable.prototype.to_a; return Enumerable; })(); RubyJS.Enumerable.SortedElement = (function() { function SortedElement(value, sort_by) { this.value = value; this.sort_by = sort_by; } SortedElement.prototype['<=>'] = function(other) { var _ref1; return (_ref1 = this.sort_by) != null ? _ref1['<=>'](other.sort_by) : void 0; }; return SortedElement; })(); RubyJS.EnumerableArray = (function() { function EnumerableArray() {} EnumerableArray.prototype.map = function(block) { var ary, el, idx, len, _isArr, _ref1; if ((block != null ? block.call : void 0) == null) { return this.to_enum('map'); } _ref1 = this.__iter_vars__(), idx = _ref1[0], len = _ref1[1], ary = _ref1[2]; _isArr = R.Array.isNativeArray; if (block.length !== 1) { while (++idx < this.__native__.length) { el = this.__native__[idx]; if (typeof el === 'object' && _isArr(el)) { ary[idx] = block.apply(this, el); } else { ary[idx] = block(el); } } } else { while (++idx < this.__native__.length) { ary[idx] = block(this.__native__[idx]); } } if (len > this.__native__.length) { ary.length = idx; } return new R.Array(ary); }; EnumerableArray.prototype.__iter_vars__ = function(no_array) { var len; len = this.__native__.length; if (no_array) { return [-1, len]; } else { return [-1, len, nativeArray(len)]; } }; EnumerableArray.prototype.inject = function(initial, sym, block) { var args, idx, _ref1; _ref1 = this.__inject_args__(initial, sym, block), initial = _ref1[0], sym = _ref1[1], block = _ref1[2]; idx = -1; while (++idx < this.__native__.length) { args = this.__native__[idx]; if (initial === void 0) { initial = args; } else { initial = block.call(this, initial, args); } } return initial; }; EnumerableArray.prototype.__apply_block__ = function(block, item) { if (block.length !== 1 && ((item.is_array != null) || R.Array.isNativeArray(item))) { return block.apply(this, item); } else { return block.call(this, item); } }; EnumerableArray.prototype.each_entry = function(block) { var idx; if (arguments.length > 1) { throw R.ArgumentError["new"](); } if (!(block && (block.call != null))) { return this.to_enum('each_entry'); } idx = -1; while (++idx < this.__native__.length) { this.__apply_block__(block, this.__native__[idx]); } return this; }; EnumerableArray.prototype.each_with_index = function(block) { var idx, item; if (!(block && (block.call != null))) { return this.to_enum('each_with_index'); } idx = -1; while (++idx < this.__native__.length) { item = this.__native__[idx]; block(item, idx); } return this; }; EnumerableArray.prototype.each_with_object = function(obj, block) { var idx; if (!(block && (block.call != null))) { return this.to_enum('each_with_object', obj); } idx = -1; while (++idx < this.__native__.length) { block(this.__native__[idx], obj); } return obj; }; EnumerableArray.prototype.find = function(ifnone, block) { var idx, item, len; if (block == null) { block = null; } if (block === null) { block = ifnone; ifnone = null; } idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (!R.falsey(this.__apply_block__(block, item))) { return item; } } return typeof ifnone === "function" ? ifnone() : void 0; }; EnumerableArray.prototype.find_all = function(block) { var ary, idx, item, len; if (!(block && (block.call != null))) { return this.to_enum('find_all'); } ary = []; idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (!R.falsey(this.__apply_block__(block, item))) { ary.push(item); } } return new R.Array(ary); }; EnumerableArray.prototype.find_index = function(value) { var block, idx, item, len; if (arguments.length === 0) { return this.to_enum('find_index'); } value = this.box(value); if (value.call != null) { block = value; } else { block = function(el) { return R(el)['=='](value) || el === value; }; } idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (this.__apply_block__(block, item)) { return R(idx); } } return null; }; EnumerableArray.prototype.include = function(other) { var el, idx, item, len; other = R(other); idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; el = R(item); if ((typeof other['=='] === "function" ? other['=='](el) : void 0) || (typeof el['=='] === "function" ? el['=='](other) : void 0)) { return true; } } return false; }; EnumerableArray.prototype.grep = function(pattern, block) { var ary, idx, item, len; ary = new R.Array([]); pattern = R(pattern); idx = -1; len = this.__native__.length; if (block) { while (++idx < len) { item = this.__native__[idx]; if (pattern['==='](item)) { ary.append(this.__apply_block__(block, item)); } } } else { while (++idx < len) { item = this.__native__[idx]; if (pattern['==='](item)) { ary.append(item); } } } return ary; }; EnumerableArray.prototype.group_by = function(block) { var hsh, idx, item, key, len; if ((block != null ? block.call : void 0) == null) { return this.to_enum('group_by'); } hsh = {}; idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; key = this.__apply_block__(block, item); hsh[key] || (hsh[key] = new R.Array([])); hsh[key].append(item); } return hsh; }; EnumerableArray.prototype.max = function(block) { var arr, comp, idx, item, len, max, _max; max = void 0; block || (block = RubyJS.Comparable.cmp); if (typeof this.__samesame__ === "function" ? this.__samesame__() : void 0) { arr = this.__native__; if (arr.length < 65535) { _max = Math.max.apply(Math, arr); if (_max !== NaN) { return _max; } } } idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (max === void 0) { max = item; } else { comp = block(item, max); if (comp === null) { throw R.ArgumentError["new"](); } if (comp > 0) { max = item; } } } return max || null; }; EnumerableArray.prototype.max_by = function(block) { var cmp, idx, item, len, max; if ((block != null ? block.call : void 0) == null) { return this.to_enum('max_by'); } max = void 0; idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (max === void 0) { max = item; } else { cmp = R.Comparable.cmpstrict(block(item), block(max)); if (cmp > 0) { max = item; } } } return max || null; }; EnumerableArray.prototype.min = function(block) { var arr, cmp, idx, item, len, min, _min; min = void 0; block || (block = RubyJS.Comparable.cmp); if (typeof this.__samesame__ === "function" ? this.__samesame__() : void 0) { arr = this.__native__; if (arr.length < 65535) { _min = Math.min.apply(Math, arr); if (_min !== NaN) { return _min; } } } idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (min === void 0) { min = item; } else { cmp = block(item, min); if (cmp === null) { throw R.ArgumentError["new"](); } if (cmp < 0) { min = item; } } } return min || null; }; EnumerableArray.prototype.min_by = function(block) { var cmp, idx, item, len, min; if ((block != null ? block.call : void 0) == null) { return this.to_enum('min_by'); } min = void 0; block || (block = function(el, min) { return el['<=>'](min); }); idx = -1; len = this.__native__.length; while (++idx < len) { item = this.__native__[idx]; if (min === void 0) { min = item; } else { cmp = RubyJS.Comparable.cmpstrict(block(item), block(min)); if (cmp < 0) { min = item; } } } return min || null; }; EnumerableArray.prototype.minmax = function(block) { return R([this.min(block), this.max(block)]); }; EnumerableArray.prototype.minmax_by = function(block) { if ((block != null ? block.call : void 0) == null) { return this.to_enum('minmax_by'); } return R([this.min_by(block), this.max_by(block)]); }; EnumerableArray.prototype.collectConcat = EnumerableArray.prototype.collect_concat; EnumerableArray.prototype.dropWhile = EnumerableArray.prototype.drop_while; EnumerableArray.prototype.eachCons = EnumerableArray.prototype.each_cons; EnumerableArray.prototype.eachEntry = EnumerableArray.prototype.each_entry; EnumerableArray.prototype.eachSlice = EnumerableArray.prototype.each_slice; EnumerableArray.prototype.eachWithIndex = EnumerableArray.prototype.each_with_index; EnumerableArray.prototype.eachWithObject = EnumerableArray.prototype.each_with_object; EnumerableArray.prototype.findAll = EnumerableArray.prototype.find_all; EnumerableArray.prototype.findIndex = EnumerableArray.prototype.find_index; EnumerableArray.prototype.flatMap = EnumerableArray.prototype.flat_map; EnumerableArray.prototype.groupBy = EnumerableArray.prototype.group_by; EnumerableArray.prototype.maxBy = EnumerableArray.prototype.max_by; EnumerableArray.prototype.minBy = EnumerableArray.prototype.min_by; EnumerableArray.prototype.minmaxBy = EnumerableArray.prototype.minmax_by; EnumerableArray.prototype.reverseEach = EnumerableArray.prototype.reverse_each; EnumerableArray.prototype.sliceBefore = EnumerableArray.prototype.slice_before; EnumerableArray.prototype.sortBy = EnumerableArray.prototype.sort_by; EnumerableArray.prototype.takeWhile = EnumerableArray.prototype.take_while; EnumerableArray.prototype.toA = EnumerableArray.prototype.to_a; return EnumerableArray; })(); RubyJS.Enumerator = (function(_super) { __extends(Enumerator, _super); Enumerator.include(RubyJS.Enumerable); Enumerator["new"] = function() { var args, iter, obj; obj = arguments[0], iter = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; return new RubyJS.Enumerator(obj, iter, args); }; function Enumerator(object, iter, args) { this.object = object; this.iter = iter != null ? iter : 'each'; this.args = args != null ? args : []; this.generator = null; this.length = this.object.length; this.idx = 0; } Enumerator.create = function() { var args, block, iter, object; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (block = R.__extract_block(args)) { object = new RubyJS.Enumerator.Generator(block); iter = 'each'; return Enumerator["new"](object, iter); } }; Enumerator.prototype.is_enumerator = function() { return true; }; Enumerator.prototype.each = function(block) { var _ref1; return (_ref1 = this.object)[this.iter].apply(_ref1, __slice.call(this.args).concat([block])); }; Enumerator.prototype.each_with_index = function(block) { var idx; if (!(block && (block.call != null))) { return this.to_enum('each_with_index'); } idx = 0; return this.each(function() { var args, val; args = $args(arguments); val = block.call(this, args, idx); idx += 1; return val; }); }; Enumerator.prototype.size = function() { return this.object.length; }; Enumerator.prototype.iterator = function() { return this.to_a().unbox(); }; Enumerator.prototype.native_array = function() { return this.arr || (this.arr = this.iterator()); }; Enumerator.prototype.next = function() { var idx; idx = this.idx; this.idx += 1; return this.native_array()[idx]; }; Enumerator.prototype.to_enum = function() { var args, iter; iter = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (iter == null) { iter = "each"; } return new RubyJS.Enumerator(this, iter, args); }; Enumerator.prototype.eachWithIndex = Enumerator.prototype.each_with_index; return Enumerator; })(RubyJS.Object); RubyJS.Enumerator.Yielder = (function(_super) { __extends(Yielder, _super); function Yielder(proc) { this.proc = proc; if (this.proc.call == null) { throw 'LocalJumpError'; } } Yielder.prototype["yield"] = function() { return this.proc.apply(this, arguments); }; Yielder.prototype['<<'] = function(value) { this["yield"](value); return this; }; return Yielder; })(RubyJS.Object); RubyJS.Enumerator.Generator = (function(_super) { __extends(Generator, _super); function Generator(proc) { this.proc = proc; if (this.proc.call == null) { throw 'LocalJumpError'; } } Generator.prototype.each = function(block) { var enclosed_yield; enclosed_yield = function() { return block.apply(this, arguments); }; return this.proc(new RubyJS.Enumerator.Yielder(enclosed_yield)); }; return Generator; })(RubyJS.Object); RubyJS.Array = (function(_super) { __extends(Array, _super); Array.include(RubyJS.Enumerable); Array.include(RubyJS.EnumerableArray, true); Array.prototype.is_array = function() { return true; }; Array.prototype.iterator = function() { return this.__native__; }; function Array(__native__, recursive) { var idx, len; this.__native__ = __native__ != null ? __native__ : []; if (recursive === true) { idx = -1; len = this.__native__.length; while (++idx < len) { this.__native__[idx] = R(this.__native__[idx], recursive); } } } Array["new"] = function() { var args, ary, block, idx, obj, size; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = R.__extract_block(args); if (args.length >= 3) { throw R.ArgumentError["new"](); } size = args[0]; obj = args[1]; if (size === void 0) { return new R.Array([]); } if (obj !== void 0 && (this.isNativeArray(size) || (size.is_array != null))) { throw R.TypeError["new"](); } if (this.isNativeArray(size)) { return new R.Array(size); } if ((size.to_ary != null) && obj === void 0) { return size.to_ary(); } size = CoerceProto.to_int_native(size); if (size < 0) { throw R.ArgumentError["new"](); } if (obj === void 0) { obj = null; } ary = []; idx = -1; while (++idx < size) { ary[idx] = block ? block(R(idx)) : obj; } return new R.Array(ary); }; Array.typecast = function(arr, recursive) { return new RubyJS.Array(arr, recursive); }; Array.isNativeArray = nativeArray.isArray || function(obj) { return _toString_.call(obj) === '[object Array]'; }; Array.try_convert = function(obj) { if (obj.is_array != null) { return obj; } if (this.isNativeArray(obj)) { return this["new"](obj); } if (obj.to_ary != null) { return obj.to_ary(); } else { return null; } }; Array.prototype.valueOf = function() { return this.__native__; }; Array.prototype.to_native = function(recursive) { var el, _i, _len, _ref1, _results; if (recursive == null) { recursive = false; } if (recursive) { _ref1 = this.__native__; _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { el = _ref1[_i]; if (el && (el.to_native != null)) { el = el.to_native(true); } _results.push(el); } return _results; } else { return this.__native__.slice(0); } }; Array.prototype.unbox = function(recursive) { var el, _i, _len, _ref1, _results; if (recursive == null) { recursive = false; } if (recursive) { _ref1 = this.__native__; _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { el = _ref1[_i]; if (el && (el.unbox != null)) { el = el.unbox(true); } _results.push(el); } return _results; } else { return this.__native__.slice(0); } }; Array.prototype.to_native_clone = function() { return this.__native__.slice(0); }; Array.prototype['=='] = function(other) { var i, md, od, total; if (this === other) { return true; } if (other == null) return false;; other = R(other); if (other.is_array == null) { if (other.to_ary == null) { return false; } return other['=='](this); } if (!this.size().equals(other.size())) { return false; } md = this.to_native_clone(); od = other.to_native(); i = 0; total = i + this.size().to_native(); while (i < total) { if (!R(md[i])['=='](R(od[i]))) { return false; } i += 1; } return true; }; Array.prototype['<<'] = function(obj) { this.__native__.push(obj); return this; }; Array.prototype['&'] = function(other) { var arr; other = CoerceProto.to_ary(other); arr = new R.Array([]); this.each(function(el) { if (other.include(el)) { return arr.push(el); } }); return arr.uniq(); }; Array.prototype['<=>'] = function(other) { if (other == null) return null;; var diff, i, other_total, total; try { other = CoerceProto.to_ary(other); } catch (e) { return null; } if (this.equals(other)) { return 0; } other_total = other.size(); i = 0; total = other_total.lt(this.size()) ? other_total : this.size(); while (total.gt(i)) { diff = R(this.__native__[i])['<=>'](other.__native__[i]); if (diff !== 0) { return diff; } i += 1; } return this.size()['<=>'](other_total); }; Array.prototype.at = function(index) { index = CoerceProto.to_int_native(index); if (index < 0) { return this.__native__[this.__size__() + index]; } else { return this.__native__[index]; } }; Array.prototype.clear = function() { this.__ensure_args_length(arguments, 0); this.replace([]); return this; }; Array.prototype.clone = function() { return this.dup(); }; Array.prototype.collect_bang = function(block) { if ((block != null ? block.call : void 0) == null) { return this.to_enum('collect_bang'); } return this.replace(this.collect(block)); }; Array.prototype.combination = function() { var args, block, chosen, done, i, lev, num, stack; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); num = CoerceProto.to_int_native(args[0]); if ((block != null ? block.call : void 0) == null) { return this.to_enum('combination', num); } if (num === 0) { block([]); } else if (num === 1) { this.each(function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return block.call(this, args); }); } else if (num === +this.size()) { block(this.dup()); } else if (num >= 0 && num < this.size()) { num = num; stack = (function() { var _i, _ref1, _results; _results = []; for (i = _i = 0, _ref1 = num + 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) { _results.push(0); } return _results; })(); chosen = []; lev = 0; done = false; stack[0] = -1; while (!done) { chosen[lev] = this.at(stack[lev + 1]); while (lev < num - 1) { lev += 1; stack[lev + 1] = stack[lev] + 1; chosen[lev] = this.at(stack[lev + 1]); } block.call(this, chosen.slice(0)); lev += 1; done = lev === 0; stack[lev] += 1; lev = lev - 1; while (stack[lev + 1] + num === this.__size__() + lev + 1) { done = lev === 0; stack[lev] += 1; lev = lev - 1; } } } return this; }; Array.prototype.compact = function() { return this.dup().tap(function(a) { return a.compact_bang(); }); }; Array.prototype.compact_bang = function() { var arr, length; length = this.__native__.length; arr = []; this.each(function(el) { if (el !== null) { return arr.push(el); } }); this.replace(arr); if (length === arr.length) { return null; } else { return this; } }; Array.prototype.concat = function(other) { other = R(other).to_ary(); return this.replace(this.__native__.concat(other.to_native())); }; Array.prototype["delete"] = function() { var args, block, deleted, i, obj, orig, total, _i, _len, _ref1; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); orig = args[0]; obj = R(orig); total = this.__native__.length; deleted = []; i = 0; while (i < total) { if (obj.equals(this.__native__[i])) { deleted.push(i); } i += 1; } if (deleted.length > 0) { _ref1 = deleted.reverse(); for (_i = 0, _len = _ref1.length; _i < _len; _i++) { i = _ref1[_i]; this.delete_at(i); } return orig; } if (block) { return block(); } else { return null; } }; Array.prototype.delete_at = function(idx) { var val; idx = CoerceProto.to_int_native(idx); if (idx < 0) { idx = idx + this.__size__(); } if (idx < 0 || idx >= this.__size__()) { return null; } val = this.__native__[idx]; this.replace(this.__native__.slice(0, idx).concat(this.__native__.slice(idx + 1))); return val; }; Array.prototype.delete_if = function(block) { return this.replace(this.reject(block)); }; Array.prototype.dup = function() { return new RubyJS.Array(this.__native__.slice(0)); }; Array.prototype.eql = function(other) { var other_arr; if (this.equals(other)) { return true; } other = R(other); if (other.is_array == null) { return false; } if (!this.size().equals(other.size())) { return false; } other_arr = other.to_native(); return this.catch_break(function(breaker) { var i; i = 0; this.each(function(x) { if (!R(x).eql(other_arr[i])) { breaker["break"](false); } return i += 1; }); return true; }); }; Array.prototype.each_index = function(block) { var idx, len; if (block && (block.call != null)) { idx = -1; len = this.__native__.length; while (++idx < len) { block(idx); } return this; } else { return this.to_enum('each_index'); } }; Array.prototype.each = function(block) { var el, idx; if (block && (block.call != null)) { idx = -1; if (block.length > 1) { while (++idx < this.__native__.length) { el = this.__native__[idx]; if (R.Array.isNativeArray(el)) { block.apply(this, el); } else { block(el); } } } else { while (++idx < this.__native__.length) { block(this.__native__[idx]); } } return this; } else { return this.to_enum(); } }; Array.prototype.get = function(a, b) { return this.slice(a, b); }; Array.prototype.set = function(idx, obj) { if (idx.is_range != null) { return this.set$range(idx, obj); } if (arguments.length === 3) { return this.set$int$int.apply(this, arguments); } idx = CoerceProto.to_int_native(idx); this.__native__[idx] = obj; return obj; }; Array.prototype.set$range = function(rng, obj) { throw R.NotImplementedError["new"](); }; Array.prototype.set$int$int = function(start, length, obj) { throw R.NotImplementedError["new"](); }; Array.prototype.empty = function() { return this.__native__.length === 0; }; Array.prototype.fetch = function() { var args, block, idx, len, orig, _default; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); orig = args[0]; idx = CoerceProto.to_int_native(args[0]); _default = args[1]; len = this.__size__(); if (idx < 0) { idx = idx + len; } if (idx < 0 || idx >= len) { if ((block != null ? block.call : void 0) != null) { return block(orig); } if (_default !== void 0) { return _default; } throw R.IndexError["new"](); } return this.at(idx); }; Array.prototype.fill = function() { var args, block, fill, i, left, obj, one, right, size, total, two, v; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (args.length === 0) { throw R.ArgumentError["new"](); } block = this.__extract_block(args); if (block) { if (args.length >= 3) { throw R.ArgumentError["new"](); } one = args[0]; two = args[1]; } else { if (args.length > 3) { throw R.ArgumentError["new"](); } obj = args[0]; one = args[1]; two = args[2]; } size = this.__size__(); if ((one != null ? one.is_range : void 0) != null) { throw R.NotImplementedError["new"](); } else if (one !== void 0 && one !== null) { left = CoerceProto.to_int_native(one); if (left < 0) { left = left + size; } if (left < 0) { left = 0; } if (two !== void 0 && two !== null) { try { right = CoerceProto.to_int_native(two); } catch (e) { throw R.ArgumentError["new"]("second argument must be a Fixnum"); } if (right === 0) { return this; } right = right + left; } else { right = size; } } else { left = 0; right = size; } total = right; if (right > size) { fill = this.__native_array_with__(right - size, null); this.concat(fill); total = right; } i = left; if (block) { while (total > i) { v = block.call(this, i); this.__native__[i] = v === void 0 ? null : v; i += 1; } } else { while (total > i) { this.__native__[i] = obj; i += 1; } } return this; }; Array.prototype.flatten = function(recursion) { var arr; if (recursion == null) { recursion = -1; } recursion = R(recursion); arr = new R.Array([]); this.each(function(el) { el = R(el); if (((el != null ? el.to_ary : void 0) != null) && !recursion.equals(0)) { return el.to_ary().flatten(recursion.minus(1)).each(function(e) { return arr.push(e); }); } else { return arr.push(el); } }); return arr; }; Array.prototype.insert = function() { var after, before, fill, idx, items; idx = arguments[0], items = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (idx === void 0) { throw R.ArgumentError["new"](); } if (items.length === 0) { return this; } idx = CoerceProto.to_int_native(idx); if (idx < 0) { idx = idx + this.__size__() + 1; } if (idx < 0) { throw R.IndexError["new"](); } before = this.__native__.slice(0, idx); if (idx > before.length) { fill = this.__native_array_with__(idx - before.length, null); before = before.concat(fill); } after = this.__native__.slice(idx); return this.replace(before.concat(items).concat(after)); }; Array.prototype.inspect = function() { return R("[" + (this.map(function(e) { return R.inspect(e); }).join(', ')) + "]"); }; Array.prototype.join = function(separator) { if (this.empty()) { return R(''); } if (separator === void 0) { separator = R['$,']; } if (separator === null) { separator = ''; } separator = CoerceProto.to_str_native(separator); return new R.String(this.__native__.join(separator)); }; Array.prototype.keep_if = function(block) { var ary; if ((block != null ? block.call : void 0) == null) { return this.to_enum('keep_if'); } ary = []; this.each(function(el) { if (!R.falsey(block(el))) { return ary.push(el); } }); if (this.__size__() === ary.length) { return this; } else { return this.replace(ary); } }; Array.prototype.minus = function(other) { var ary; other = CoerceProto.to_ary(other); ary = []; this.each(function(el) { if (!other.include(el)) { return ary.push(el); } }); return new R.Array(ary); }; Array.prototype.multiply = function(multiplier) { var arr, ary, idx, total; this.__ensure_args_length(arguments, 1); if (multiplier === null) { throw R.TypeError["new"](); } multiplier = R(multiplier); if (multiplier.to_str != null) { return this.join(multiplier); } else { multiplier = CoerceProto.to_int_native(multiplier); if (multiplier < 0) { throw R.ArgumentError["new"]("count cannot be negative"); } total = this.__size__(); if (total === 0) { return new R.Array([]); } else if (total === 1) { return this.dup(); } ary = []; arr = this.__native__; idx = -1; while (++idx < multiplier) { ary = ary.concat(arr); } return new R.Array(ary); } }; Array.prototype.last = function(n) { var len; len = this.__size__(); if (len < 1) { if (n === void 0) { return null; } return new R.Array([]); } if (n === void 0) { return this.at(-1); } n = CoerceProto.to_int_native(n); if (n === 0) { return new R.Array([]); } if (n < 0) { throw R.ArgumentError["new"]("count must be positive"); } if (n > len) { n = len; } return new R.Array(this.__native__.slice(-n)); }; Array.prototype.permutation = function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; throw R.NotImplementedError["new"](); }; Array.prototype.plus = function(other) { return this.concat(other); }; Array.prototype.pop = function(many) { var first; if (arguments.length > 1) { throw R.ArgumentError["new"](); } if (many === void 0) { return this.__native__.pop(); } else { many = CoerceProto.to_int_native(many); if (many < 0) { throw R.ArgumentError["new"]("negative array size"); } first = this.__size__() - many; if (first < 0) { first = 0; } return this.slice_bang(first, many); } }; Array.prototype.product = function() { var args, block, block_result, outer, result; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); args = R.$Array_r(args).reverse(); if (!args.all(function(a) { return a.to_ary != null; })) { throw R.TypeError["new"](); } args.map_bang(function(a) { return a.to_ary(); }); result = new R.Array([]); args.push(this); outer = args.inject(result.push, function(trigger, values) { return function(partial) { return values.each(function(val) { return trigger.call(result, partial.dup().append(val)); }); }; }); outer(new R.Array([])); if (block) { block_result = this; result.each(function(v) { return block_result.append(block(v)); }); return block_result; } else { return result; } }; Array.prototype.push = function() { this.__native__.push.apply(this.__native__, arguments); return this; }; Array.prototype.rassoc = function(obj) { obj = R(obj); return this.catch_break(function(breaker) { this.each(function(elem) { var _ref1; if ((elem.is_array != null) && ((_ref1 = R(elem.at(1))) != null ? _ref1['=='](obj) : void 0)) { return breaker["break"](elem); } }); return null; }); }; Array.prototype.rindex = function(other) { var block, len, ridx; if (other === void 0) { return this.to_enum('rindex'); } if (other.call != null) { block = other; len = this.__size__(); ridx = this.catch_break(function(breaker) { var idx; idx = -1; this.reverse_each(function(el) { idx += 1; if (!R.falsey(block(el))) { return breaker["break"](idx); } }); return null; }); } else { ridx = this.catch_break(function(breaker) { var idx; idx = -1; this.reverse_each(function(el) { idx += 1; if (R(el)['=='](other)) { return breaker["break"](idx); } }); return null; }); } if (ridx === null) { return null; } else { return R(this.__size__() - ridx - 1); } }; Array.prototype.sample = function(n, range) { var ary, idx, ridx, size, tmp; if (range == null) { range = void 0; } if (n === void 0) { return this.at(this.rand(this.size())); } n = CoerceProto.to_int_native(n); if (n < 0) { throw R.ArgumentError["new"](); } size = this.__size__(); if (n > size) { n = size; } ary = this.to_native_clone(); idx = -1; while (++idx < n) { ridx = idx + R.rand(size - idx); tmp = ary[idx]; ary[idx] = ary[ridx]; ary[ridx] = tmp; } return new R.Array(ary).slice(0, n); }; Array.prototype.reject_bang = function(block) { var ary; if ((block != null ? block.call : void 0) == null) { return this.to_enum('reject_bang'); } ary = this.reject(block); if (ary.__size__() === this.__size__()) { return null; } else { return this.replace(ary); } }; Array.prototype.replace = function(val) { this.__ensure_args_length(arguments, 1); this.__native__ = val.to_ary != null ? val.to_ary().to_native().slice(0) : val.slice(0); return this; }; Array.prototype.reverse = function() { return this.dup().tap(function(w) { return w.reverse_bang(); }); }; Array.prototype.reverse_bang = function() { this.replace(this.__native__.reverse()); return this; }; Array.prototype.reverse_each = function(block) { var arr, el, idx; if (!(block && (block.call != null))) { return this.to_enum('reverse_each'); } if (block && (block.call != null)) { arr = this.__native__; idx = arr.length; if (block.length > 1) { while (idx--) { el = arr[idx]; if (R.Array.isNativeArray(el)) { block.apply(this, el); } else { block(el); } } } else { while (idx--) { block(arr[idx]); } } return this; } else { return this.to_enum(); } }; Array.prototype.rotate = function(cnt) { var ary, idx, sliced; if (cnt === void 0) { cnt = 1; } cnt = CoerceProto.to_int_native(cnt); ary = this.dup(); if (this.__size__() === 1) { return ary; } if (this.empty()) { return new R.Array([]); } idx = cnt % ary.__size__(); sliced = ary.slice(R.rng(0, idx, true)); return ary.slice(R.rng(idx, -1)).concat(sliced); }; Array.prototype.rotate_bang = function(cnt) { if (cnt === void 0) { cnt = 1; return this.replace(this.rotate(cnt)); } else { cnt = CoerceProto.to_int_native(cnt); if (cnt === 0 || cnt === 1) { return this; } return this.replace(this.rotate(cnt)); } }; Array.prototype.select_bang = function(block) { var ary; if ((block != null ? block.call : void 0) == null) { return this.to_enum('select_bang'); } ary = this.select(block); if (ary.__size__() === this.__size__()) { return null; } else { return this.replace(ary); } }; Array.prototype.shift = function(n) { var el, ret; if (arguments.length > 1) { throw R.ArgumentError["new"](); } if (n === void 0) { el = this.__native__[0]; this.replace(this.__native__.slice(1)); return el; } else { n = CoerceProto.to_int_native(n); if (n < 0) { throw R.ArgumentError["new"](); } ret = this.first(n); this.replace(this.__native__.slice(n)); return ret; } }; Array.prototype.shuffle = function() { return this.dup().tap(function(ary) { return ary.shuffle_bang(); }); }; Array.prototype.shuffle_bang = function() { var arr, idx, rnd, size, tmp; size = this.__size__(); arr = this.__native__; idx = -1; while (++idx < size) { rnd = idx + R.rand(size - idx); tmp = arr[idx]; arr[idx] = arr[rnd]; arr[rnd] = tmp; } return this; }; Array.prototype.size = function() { return R(this.__native__.length); }; Array.prototype.__size__ = function() { return this.__native__.length; }; Array.prototype.slice = function(idx, length) { var range, range_end, range_lenth, range_start, size; if (idx === null) { throw new R.TypeError["new"](); } size = this.__size__(); if ((idx != null ? idx.is_range : void 0) != null) { range = idx; range_start = CoerceProto.to_int_native(range.begin()); range_end = CoerceProto.to_int_native(range.end()); if (range_start < 0) { range_start = range_start + size; } if (range_end < 0) { range_end = range_end + size; } if (!range.exclude_end()) { range_end = range_end + 1; } range_lenth = range_end - range_start; if (range_start > size || range_start < 0) { return null; } return new R.Array(this.__native__.slice(range_start, range_end)); } else { idx = CoerceProto.to_int_native(idx); } if (idx < 0) { idx = size + idx; } if (length === void 0) { if (idx < 0 || idx >= size) { return null; } return this.at(idx); } else { length = CoerceProto.to_int_native(length); if (idx < 0 || idx > size || length < 0) { return null; } return new R.Array(this.__native__.slice(idx, length + idx)); } }; Array.prototype.slice_bang = function(idx, length) { var ary, range, rng_end, rng_length, rng_start, size; if (idx === null) { throw new R.TypeError["new"](); } ary = null; size = this.__size__(); if (idx.is_range != null) { range = idx; ary = this.slice(range); rng_start = CoerceProto.to_int_native(range.begin()); rng_end = CoerceProto.to_int_native(range.end()); if (rng_start < 0) { rng_start = rng_start + size; } if (rng_end < 0) { rng_end = rng_end + size; } else if (rng_end >= size) { rng_end >= size; } rng_length = rng_end - rng_start; if (!range.exclude_end()) { rng_length = rng_length + 1; } if (rng_start < size && rng_start >= 0 && rng_end <= size && rng_end >= 0 && rng_length > 0) { this.__delete_range(rng_start, rng_length); } } else if (length !== void 0) { idx = CoerceProto.to_int_native(idx); length = CoerceProto.to_int_native(length); if (idx > size) { return null; } if (length === 0) { return new R.Array([]); } ary = this.slice(idx, length); this.__delete_range(idx, length); } else { idx = CoerceProto.to_int_native(idx); ary = this.delete_at(idx); } return ary; }; Array.prototype.__delete_range = function(start, length) { var new_ary, size; size = this.__size__(); if (start > size || start < 0) { return null; } if (size < (start + length)) { new_ary = new R.Array([]); } else { new_ary = this.slice(0, start).concat(this.slice(start + length, size) || []); } if (new_ary.__size__() !== this.__size__()) { return this.replace(new_ary); } }; Array.prototype.sort_bang = function(block) { return this.replace(this.sort(block)); }; Array.prototype.sort_by_bang = function(block) { if ((block != null ? block.call : void 0) == null) { return this.to_enum('sort_by_bang'); } return this.replace(this.sort_by(block)); }; Array.prototype.transpose = function() { var max, out; if (this.empty()) { return new R.Array([]); } out = new R.Array([]); max = null; this.each(function(ary) { var entry, idx, len, _results; ary = CoerceProto.to_ary(ary); max || (max = ary.size()); if (!ary.size().equals(max)) { throw R.IndexError["new"](); } idx = -1; len = ary.__size__(); _results = []; while (++idx < len) { if (!out.at(idx)) { out.append(new R.Array([])); } entry = out.at(idx); _results.push(entry.append(ary.at(idx))); } return _results; }); return out; }; Array.prototype.uniq = function() { var arr; arr = new R.Array([]); this.each(function(el) { if (!arr.include(el)) { return arr.push(el); } }); return arr; }; Array.prototype.uniq_bang = function(block) { var ary; ary = this.uniq(); if (ary.__size__() === this.__size__()) { return null; } else { return this.replace(ary); } }; Array.prototype.unshift = function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return this.replace(args.concat(this.__native__)); }; Array.prototype.union = function(other) { return this.plus(other).uniq(); }; Array.prototype.to_enum = function() { var args, iter; iter = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (iter == null) { iter = "each"; } return new RubyJS.Enumerator(this, iter, args); }; Array.prototype.to_ary = function() { return this; }; Array.prototype.values_at = function() { var args, ary, idx; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; ary = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = args.length; _i < _len; _i++) { idx = args[_i]; _results.push(this.at(CoerceProto.to_int_native(idx)) || null); } return _results; }).call(this); return new R.Array(ary); }; Array.__add_default_aliases__(Array.prototype); Array.prototype.map_bang = Array.prototype.collect_bang; Array.prototype.index = Array.prototype.find_index; Array.prototype.each_for = Array.prototype.each; Array.prototype['|'] = Array.prototype.union; Array.prototype.to_s = Array.prototype.inspect; Array.prototype.intersection = Array.prototype['&']; Array.prototype.deleteAt = Array.prototype.delete_at; Array.prototype.deleteIf = Array.prototype.delete_if; Array.prototype.dropWhile = Array.prototype.drop_while; Array.prototype.eachIndex = Array.prototype.each_index; Array.prototype.equalValue = Array.prototype.equal_value; Array.prototype.findIndex = Array.prototype.find_index; Array.prototype.intersection = Array.prototype.intersection; Array.prototype.keepIf = Array.prototype.keep_if; Array.prototype.reverse_each = Array.prototype.reverse_each; Array.prototype.sortBy = Array.prototype.sort_by; Array.prototype.takeWhile = Array.prototype.take_while; Array.prototype.toA = Array.prototype.to_a; Array.prototype.toAry = Array.prototype.to_ary; Array.prototype.toS = Array.prototype.to_s; Array.prototype.tryConvert = Array.prototype.try_convert; Array.prototype.valuesAt = Array.prototype.values_at; Array.prototype.__native_array_with__ = function(size, obj) { var ary, idx; ary = nativeArray(CoerceProto.to_int_native(size)); idx = -1; while (++idx < size) { ary[idx] = obj; } return ary; }; return Array; })(RubyJS.Object); RubyJS.Hash = (function(_super) { __extends(Hash, _super); Hash.include(RubyJS.Enumerable); Hash["new"] = function() { return new RubyJS.Hash(); }; function Hash(obj) {} return Hash; })(RubyJS.Object); RubyJS.Range = (function(_super) { __extends(Range, _super); Range.include(RubyJS.Enumerable); Range["new"] = function(start, end, exclusive) { if (exclusive == null) { exclusive = false; } return new RubyJS.Range(start, end, exclusive); }; function Range(start, end, exclusive) { this.exclusive = exclusive != null ? exclusive : false; this.__start__ = this.box(start); this.__end__ = this.box(end); if (!((this.__start__.is_fixnum != null) && (this.__end__.is_fixnum != null))) { try { if (this.__start__['<=>'](this.__end__) === null) { throw R.ArgumentError["new"](); } } catch (err) { throw R.ArgumentError["new"](); } } this.comparison = this.exclusive ? '<' : '<='; } Range.prototype.is_range = function() { return true; }; Range.prototype.iterator = function() { var arr; arr = []; this.each(function(e) { return arr.push(e); }); return arr; }; Range.prototype['=='] = function(other) { if (!(other instanceof RubyJS.Range)) { return false; } return this.__end__['=='](other.end()) && this.__start__['=='](other.start()) && this.exclusive === other.exclude_end(); }; Range.prototype.equals = Range.prototype['==']; Range.prototype.begin = function(obj) { return this.__start__; }; Range.prototype.cover = function(obj) { if (arguments.length !== 1) { throw RubyJS.ArgumentError["new"](); } obj = obj; if (obj === null) { return false; } return this.equal_case(obj); }; Range.prototype['==='] = function(other) { var e, s; other = R(other); s = other['<=>'](this.__start__); e = other['<=>'](this.__end__); if (s === null && e === null) { return false; } s = -s; e = -e; return s <= 0 && (this.exclusive ? e > 0 : e >= 0); }; Range.prototype.each = function(block) { var iterator; if (!(block && (block.call != null))) { return this.to_enum('each'); } if (this.begin().succ == null) { throw R.TypeError["new"]("can't iterate from " + (this.begin())); } iterator = this.__start__.dup(); while (iterator[this.comparison](this.__end__)) { block(iterator); iterator = iterator.succ(); } return this; }; Range.prototype.end = function() { return this.__end__; }; Range.prototype.exclude_end = function() { return this.exclusive; }; Range.prototype.first = function(n) { return this.begin(); }; Range.prototype.inspect = function() { var sep; sep = this.exclude_end() ? "..." : ".."; return "" + (this.start().inspect()) + sep + (this.end().inspect()); }; Range.prototype.min = function(block) { var b, e; if ((block != null ? block.call : void 0) != null) { return R.Enumerable.prototype.min.call(this, block); } b = this.begin(); e = this.end(); if (e['<'](b) || (this.exclusive && e.equals(b))) { return null; } if (b.is_float != null) { return b; } return R.Enumerable.prototype.min.call(this); }; Range.prototype.max = function(block) { var b, e; if ((block != null ? block.call : void 0) != null) { return R.Enumerable.prototype.max.call(this, block); } b = this.begin(); e = this.end(); if (e['<'](b) || (this.exclusive && e.equals(b))) { return null; } if ((e.is_float != null) || ((e.is_float != null) && !this.exclusive)) { return e; } return R.Enumerable.prototype.max.call(this); }; Range.prototype.start = function() { return this.__start__; }; Range.prototype.step = function(step_size, block) { var cmp, cnt, first, last; if (step_size == null) { step_size = 1; } if (arguments.length === 1 && (step_size.call != null)) { block = step_size; step_size = 1; } if (!(block && (block.call != null))) { return this.to_enum('step', step_size); } step_size = R(step_size); first = this.begin(); last = this.end(); if (((step_size != null ? step_size.is_float : void 0) != null) || (first.is_float != null) || (last.is_float != null)) { step_size = step_size.to_f(); first = first.to_f(); last = last.to_f(); } else { step_size = CoerceProto.to_int_native(step_size); } if (step_size <= 0) { if (step_size < 0) { throw R.ArgumentError["new"](); } throw R.ArgumentError["new"](); } cnt = first; cmp = this.exclude_end() ? '<' : '<='; if (first.is_float != null) { while (cnt[cmp](last)) { block(cnt); cnt = cnt.plus(step_size); } } else if (first.is_fixnum != null) { while (cnt[cmp](last)) { block(cnt); cnt = cnt.plus(step_size); } } else { cnt = 0; this.each(function(o) { if (cnt % step_size === 0) { block(R(o)); } return cnt += 1; }); } return this; }; Range.prototype.to_a = function() { if ((this.__end__.is_float != null) && (this.__start__.is_float != null)) { throw RubyJS.TypeError["new"](); } return RubyJS.Enumerable.prototype.to_a.apply(this); }; Range.prototype.to_s = Range.prototype.inspect; Range.__add_default_aliases__(Range.prototype); Range.prototype.eql = Range.prototype['==']; Range.prototype.include = Range.prototype['===']; Range.prototype.last = Range.prototype.end; Range.prototype.member = Range.prototype.include; Range.prototype.excludeEnd = Range.prototype.exclude_end; return Range; })(RubyJS.Object); RubyJS.MatchData = (function(_super) { __extends(MatchData, _super); function MatchData(__native__, opts) { var i, m, _i, _len, _ref1; this.__native__ = __native__; if (opts == null) { opts = {}; } _ref1 = this.__native__; for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { m = _ref1[i]; this[i] = m; } this.__offset__ = opts.offset || 0; this.__source__ = opts.string; this.__regexp__ = opts.regexp; } MatchData.prototype.is_match_data = function() { return true; }; MatchData.prototype['=='] = function(other) { if (!(other.is_match_data != null)) { return false; } return this.regexp()['=='](other.regexp()) && this.string()['=='](other.string()) && this.__offset__ === other.__offset__; }; MatchData.prototype.begin = function(offset) { this.__ensure_args_length(1); return R(this.__source__.slice(this.__offset__).indexOf(this.__native__[offset]) + this.__offset__); }; MatchData.prototype.captures = function() { return R(this.__native__.slice(1)); }; MatchData.prototype.end = function(offset) { this.__ensure_args_length(1); return R(this.__source__.slice(this.__offset__).indexOf(this.__native__[offset]) + this.__offset__ + this.__native__[offset].length); }; MatchData.prototype.eql = function(other) { return this['=='](other); }; MatchData.prototype.get = function() { var args, arr; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; arr = this.to_a(); return arr.get.apply(arr, arguments); }; MatchData.prototype.inspect = function() { var results; results = R(["\"" + this[0] + "\""]); results.concat(this.captures().each_with_index().map(function(w, i) { return "" + (i + 1) + ":\"" + w + "\""; })); return new R.String("#"); }; MatchData.prototype.length = function() { return R(this.__native__.length); }; MatchData.prototype.offset = function(offset) { var b; b = this.begin(offset); return R([b.to_native(), b + this.__native__[offset].length]); }; MatchData.prototype.post_match = function() { return this.__source__.slice(this.end(0)); }; MatchData.prototype.pre_match = function() { return this.__source__.slice(0, this.begin(0)); }; MatchData.prototype.regexp = function() { return R(this.__regexp__); }; MatchData.prototype.size = function() { return this.length(); }; MatchData.prototype.string = function() { return R(this.__source__); }; MatchData.prototype.to_a = function() { return R(this.__native__); }; MatchData.prototype.to_s = function() { return R(this.__native__[0]); }; MatchData.prototype.values_at = function() { var arr, indices; indices = 1 <= arguments.length ? __slice.call(arguments, 0) : []; arr = this.to_a(); return arr.values_at.apply(arr, indices); }; MatchData.prototype.names = function() { throw RubyJS.NotSupportedError["new"](); }; MatchData.prototype.postMatch = MatchData.prototype.post_match; MatchData.prototype.preMatch = MatchData.prototype.pre_match; MatchData.prototype.valuesAt = MatchData.prototype.values_at; return MatchData; })(RubyJS.Object); nativeString = root.String; RubyJS.String = (function(_super) { __extends(String, _super); String.include(RubyJS.Comparable); String.fromCharCode = function(obj) { return nativeString.fromCharCode(obj); }; String["new"] = function(str) { if (str == null) { str = ''; } return new R.String(str); }; function String(primitive) { if (primitive == null) { primitive = ""; } if (typeof primitive !== 'string') { primitive = primitive.valueOf(); } this.replace(primitive); } String.isString = function(obj) { if (typeof obj === 'string') { return true; } if (typeof obj !== 'object') { return false; } return _toString_.call(obj) === '[object String]'; }; String.try_convert = function(obj) { if (!(this.isString(obj) || (obj.to_str != null))) { return null; } if (obj.to_str != null) { obj = obj.to_str(); if (obj === null || obj === void 0) { return null; } if (obj.is_string == null) { throw R.TypeError["new"](); } return obj; } else { return this["new"](obj); } }; String.string_native = function(obj) { if (typeof obj === 'string') { return obj; } obj = R(obj); if (obj.to_str != null) { return obj.to_str().to_native(); } else { return null; } }; String.prototype.is_string = function() { return true; }; String.prototype.to_native = function() { return this.__native__; }; String.prototype.valueOf = function() { return this.to_native(); }; String.prototype.toString = function() { return this.to_native(); }; String.prototype.unbox = function() { return this.toString(); }; String.prototype.initialize_copy = function() {}; String.prototype.clone = function() { return new this.constructor(this.to_native() + ""); }; String.prototype['%'] = function(num) { throw R.NotImplementedError["new"](); }; String.prototype['*'] = function(num) { var n, str, _i, _ref1; num = this.box(num).to_int(); this.__ensure_numeric(num); if (num.lt(0)) { throw RubyJS.ArgumentError["new"](); } str = ""; for (n = _i = 0, _ref1 = num.to_native(); 0 <= _ref1 ? _i < _ref1 : _i > _ref1; n = 0 <= _ref1 ? ++_i : --_i) { str += this; } return new R.String(str); }; String.prototype['+'] = function(other) { other = CoerceProto.to_str_native(other); return new R.String(this.to_native() + other); }; String.prototype['<=>'] = function(other) { other = R(other); if (other.to_str == null) { return null; } if (other['<=>'] == null) { return null; } if (other.is_string != null) { other = other.to_native(); if (this.to_native() === other) { return 0; } else if (this.to_native() < other) { return -1; } else { return 1; } } else { return -other['<=>'](this); } }; String.prototype['=='] = function(other) { if (other.is_string != null) { return this.to_native() === other.to_native(); } else if (String.isString(other)) { return this.to_native() === other; } else if (other.to_str != null) { return other['=='](this.to_native()); } else { return false; } }; String.prototype['<<'] = function(other) { other = this.box(other); if (other.is_integer != null) { if (other.lt(0)) { throw new Error("RangeError"); } other = other.chr(); } if ((other != null ? other.to_str : void 0) == null) { throw R.TypeError["new"](); } return this.replace(this.to_native() + other.to_str().to_native()); }; String.prototype['=~'] = function() { var args, block, offset, pattern; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); pattern = R(args[0]); if (pattern.is_string != null) { throw R.TypeError["new"](); } offset = R(args[1]); return this.match(pattern, offset, block); }; String.prototype.capitalize = function() { return this.dup().tap(function(me) { return me.capitalize_bang(); }); }; String.prototype.capitalize_bang = function() { var str; if (this.empty()) { return; } str = this.downcase(); str = str.chr().upcase().concat(str.to_native().slice(1) || ''); if (this.equals(str)) { return null; } else { return this.replace(str.to_native()); } }; String.prototype.casecmp = function(other) { var _base; other = typeof (_base = R(other)).to_str === "function" ? _base.to_str() : void 0; if (!other) { throw R.TypeError["new"](); } return this.downcase().cmp(other.downcase()); }; String.prototype.center = function(length, padString) { var lft, max, rgt, size; if (padString == null) { padString = ' '; } length = this.box(length); padString = CoerceProto.to_str(padString); this.__ensure_numeric(length); this.__ensure_string(padString); if (padString.empty()) { throw R.ArgumentError["new"](); } if (this.size().gteq(length)) { return this; } lft = (length.minus(this.size())).divide(2); rgt = length.minus(this.size()).minus(lft); max = lft.gt(rgt) ? lft : rgt; size = padString.size(); padString = padString.multiply(max); return this.$String(padString.to_native().slice(0, lft) + this.to_native() + padString.to_native().slice(0, rgt)); }; String.prototype.chars = function(block) { var idx, len; if (!(block && (block.call != null))) { return this.to_enum('chars'); } idx = -1; len = this.__native__.length; while (++idx < len) { block(this.__native__[idx]); } return this; }; String.prototype.chomp = function(sep) { if (sep == null) { sep = null; } return this.dup().tap(function(d) { return d.chomp_bang(sep); }); }; String.prototype.chomp_bang = function(sep) { var ending, regexp, _ref1; if (sep == null) { sep = null; } if (sep === null) { if (this.empty()) { return this.replace(""); } } else { sep = this.$String(sep); if (sep.empty()) { regexp = /((\r\n)|\n)+$/; } else if (sep.equals("\n") || sep.equals("\r") || sep.equals("\r\n")) { ending = ((_ref1 = this.to_native().match(/((\r\n)|\n|\r)$/)) != null ? _ref1[0] : void 0) || "\n"; regexp = new RegExp("(" + (R.Regexp.escape(ending)) + ")$"); } else { regexp = new RegExp("(" + (R.Regexp.escape(sep)) + ")$"); } this.replace(this.to_native().replace(regexp, '')); return null; } }; String.prototype.chop = function() { if (this.empty()) { return this.dup(); } if (this.end_with("\r\n")) { return new R.String(this.to_native().replace(/\r\n$/, '')); } else { return this.slice(0, this.size().minus(1)); } }; String.prototype.chr = function() { var c; c = this.empty() ? "" : this.to_native()[0]; return this.box(c); }; String.prototype.clear = function() { return this.replace(""); }; String.prototype.count = function() { var args, tbl; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (R(args.length).equals(0)) { throw RubyJS.ArgumentError["new"](); } tbl = new CharTable(args); return this.chars().count(function(chr) { return tbl.include(chr); }); }; String.prototype["delete"] = function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return this.dup().tap(function(s) { return s.delete_bang.apply(s, args); }); }; String.prototype.delete_bang = function() { var args, str, tbl; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (R(args.length).equals(0)) { throw RubyJS.ArgumentError["new"](); } tbl = new CharTable(args); str = []; R(this.to_native().split("")).each(function(chr) { if (!tbl.include(chr)) { return str.push(chr); } }); str = str.join(''); if (this.equals(str)) { return null; } return this.replace(str); }; String.prototype.downcase = function() { return this.dup().tap(function(s) { return s.downcase_bang(); }); }; String.prototype.downcase_bang = function() { if (!this.to_native().match(/[A-Z]/)) { return null; } return this.replace(R(this.__char_natives__()).map(function(c) { if (c.match(/[A-Z]/)) { return c.toLowerCase(); } else { return c; } }).join('').to_native()); }; String.prototype.dump = function() { var escaped; escaped = this.to_native().replace(/[\f]/g, '\\f').replace(/["]/g, "\\\"").replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r').replace(/[\t]/g, '\\t'); return R("\"" + escaped + "\""); }; String.prototype.dup = function() { var dup; dup = this.clone(); dup.initialize_copy(this); return dup; }; String.prototype.each_char = String.prototype.chars; String.prototype.each_line = function() { var args, block, dup, lft, remainder, rgt, separator, str; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); if (!(block && (block.call != null))) { return this.to_enum('lines', args[0]); } if (args[0] === null) { block(this); return; } separator = R(args[0] === void 0 ? R['$/'] : args[0]); if (separator.to_str == null) { throw R.TypeError["new"](); } separator = separator.to_str(); if (separator.length === 0) { separator = "\n\n"; } lft = 0; rgt = null; dup = this.dup(); while (rgt = dup.index(separator, lft)) { rgt = rgt.succ(); str = dup.slice(lft, rgt.minus(lft)); lft = rgt; block(str); } if (remainder = R(dup.to_native().slice(lft.to_native()))) { if (!remainder.empty()) { block(remainder); } } return this; }; String.prototype.empty = function() { return this.to_native().length === 0; }; String.prototype.end_with = function() { var needles, w, _i, _len, _ref1; needles = 1 <= arguments.length ? __slice.call(arguments, 0) : []; needles = this.$Array_r(needles).select(function(el) { return (el != null ? el.to_str : void 0) != null; }).map(function(w) { return w.to_str().to_native(); }); _ref1 = needles.iterator(); for (_i = 0, _len = _ref1.length; _i < _len; _i++) { w = _ref1[_i]; if (this.to_native().lastIndexOf(w) + w.length === this.to_native().length) { return true; } } return false; }; String.prototype.eql = function(other) { return this['<=>'](other) === 0; }; String.prototype.get = function() { return this.slice.apply(this, arguments); }; String.prototype.set = function(idx, other) { var chrs, index; idx = R(idx); other = CoerceProto.to_str(other); index = null; if (idx.to_int != null) { index = idx.to_int().to_native(); if (index < 0) { index += this.length; } if (index < 0 || index > this.length) { throw R.IndexError["new"](); } } else if (idx.to_str != null) { index = this.index(idx); if (!index) { throw R.IndexError["new"](); } } chrs = this.to_native().split(""); chrs[index] = other; this.replace(chrs.join('')); return other; }; String.prototype.gsub = function(pattern, replacement) { var gsubbed, pattern_lit; if (pattern === null) { throw R.TypeError["new"](); } pattern_lit = String.string_native(pattern); if (pattern_lit !== null) { pattern = new RegExp(R.Regexp.escape(pattern_lit), 'g'); } if (!R.Regexp.isRegexp(pattern)) { throw R.TypeError["new"](); } if (!pattern.global) { throw "String#gsub: " + pattern + " has not set the global flag 'g'. " + pattern + "g"; } replacement = CoerceProto.to_str(replacement).to_native(); gsubbed = this.to_native().replace(pattern, replacement); return new this.constructor(gsubbed); }; String.prototype.include = function(other) { other = CoerceProto.to_str_native(other); return this.to_native().indexOf(other) >= 0; }; String.prototype.index = function(needle, offset) { var idx; needle = R(needle); if (needle.to_str != null) { needle = needle.to_str(); } if (offset) { offset = CoerceProto.to_int(offset); if (offset.lt(0)) { offset = this.size().minus(offset.abs()); } } if (!((needle.is_string != null) || (needle.is_regexp != null) || (needle.is_fixnum != null))) { throw R.TypeError["new"](); } if (offset) { if (offset.gt(this.to_native().length) || offset.lt(0)) { return null; } } idx = this.to_native().indexOf(needle.valueOf(), +offset); if (idx < 0) { return null; } else { return new R.Fixnum(idx); } }; String.prototype.insert = function(idx, other) { var after, before, chrs, insert; idx = CoerceProto.to_int(idx); other = CoerceProto.to_str(other); idx = idx.to_native(); if (idx < 0) { idx = this.length - Math.abs(idx) + 1; } if (idx < 0 || idx > this.length) { throw R.IndexError["new"](); } chrs = this.to_native().split(""); before = chrs.slice(0, idx); insert = other.to_native().split(""); after = chrs.slice(idx); return this.replace(before.concat(insert).concat(after).join('')); }; String.prototype.inspect = function() { return this.dump(); }; String.prototype.lines = String.prototype.each_line; String.prototype.ljust = function(width, padString) { var idx, len, out, padLength; if (padString == null) { padString = " "; } width = CoerceProto.to_int_native(width); len = this.__native__.length; if (len >= width) { return this.clone(); } else { padString = CoerceProto.to_str_native(padString); if (padString.length === 0) { throw R.ArgumentError["new"](); } padLength = width - len; idx = -1; out = ""; while (++idx <= padLength) { out += padString; } return new R.String(this.__native__ + out.slice(0, padLength)); } }; String.prototype.lstrip = function() { return this.dup().tap(function(s) { return s.lstrip_bang(); }); }; String.prototype.lstrip_bang = function() { if (!this.to_native().match(/^[\s\n\t]+/)) { return null; } return this.replace(this.to_native().replace(/^[\s\n\t]+/g, '')); }; String.prototype.match = function() { var args, block, haystack, matches, offset, opts, pattern, result; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; block = this.__extract_block(args); pattern = R(args[0]); if (pattern.to_str != null) { pattern = pattern.to_str(); } if (!((pattern.is_string != null) || (pattern.is_regexp != null))) { throw R.TypeError["new"](); } haystack = this.to_native(); opts = {}; if (offset = R(args[1])) { offset = offset.to_int().to_native(); opts.string = haystack; opts.offset = offset; haystack = haystack.slice(offset); matches = haystack.match(pattern.to_native(), offset); } else { matches = haystack.match(pattern.to_native()); } result = matches ? new R.MatchData(matches, opts) : null; R['$~'] = result; if (block) { if (result) { return block(result); } else { return []; } } else { return result; } }; String.prototype.partition = function(pattern) { var a, b, c, idx, len, start; pattern = CoerceProto.to_str(pattern).to_str(); if (idx = this.index(pattern)) { start = idx + pattern.length; len = this.size() - start; a = this.slice(0, idx); b = pattern.dup(); c = R(this.to_native().slice(start)); } a || (a = this); b || (b = R("")); c || (c = R("")); return R([a, b, c]); }; String.prototype.prepend = function(other) { other = CoerceProto.to_str_native(other); return this.replace(other + this.to_native()); }; String.prototype.replace = function(val) { if (typeof val !== 'string') { val = R(val); if (val.to_str == null) { throw R.TypeError["new"](); } val = val.to_str().valueOf(); } this.__native__ = val; this.length = val.length; return this; }; String.prototype.reverse = function() { return this.dup().tap(function(me) { return me.reverse_bang(); }); }; String.prototype.reverse_bang = function() { return this.replace(this.to_native().split("").reverse().join("")); }; String.prototype.rindex = function(needle, offset) { var ret, _ref1; if (offset === null) { throw R.TypeError["new"]('TypeError'); } needle = R(needle); if (needle.to_str != null) { needle = needle.to_str(); } else if (needle.is_regexp != null) { needle = needle; } else { throw R.TypeError["new"]('TypeError'); } offset = (_ref1 = this.box(offset)) != null ? _ref1.to_int() : void 0; if (offset !== void 0) { if (offset.lt(0)) { offset = offset.plus(this.size()); } if (offset.lt(0)) { return null; } if (needle.is_string != null) { offset = offset.plus(needle.size()); ret = this.to_native().slice(0, offset).lastIndexOf(needle.to_native()); } else { ret = this.__rindex_with_regexp__(needle, offset); } } else { if (needle.is_string != null) { ret = this.to_native().lastIndexOf(needle.to_native()); } else { ret = this.__rindex_with_regexp__(needle); } } if (ret === -1) { return null; } else { return this.$Integer(ret); } }; String.prototype.__rindex_with_regexp__ = function(needle, offset) { var idx, length, match, match_begin, ret; needle = needle.to_native(); offset = this.box(offset); idx = 0; length = this.size(); match_begin = needle.toString().match(/\/\^/) !== null; ret = -1; while (match = this.to_native().slice(idx).match(needle)) { if (offset && offset < (idx + match.index)) { break; } ret = idx; idx = idx + 1; if (match_begin || idx > length) { break; } } return ret; }; String.prototype.rjust = function(width, padString) { var padLength, _base; if (padString == null) { padString = " "; } width = CoerceProto.to_int(width); if (this.length >= width) { return this.clone(); } else { padString = typeof (_base = this.box(padString)).to_str === "function" ? _base.to_str() : void 0; if ((padString != null ? padString.is_string : void 0) == null) { throw R.TypeError["new"](); } if (padString.empty()) { throw R.ArgumentError["new"](); } padLength = width.minus(this.length); return this.$String(padString.multiply(padLength).to_native().slice(0, padLength) + this); } }; String.prototype.rpartition = function(pattern) { var a, b, c, idx, len, start; pattern = CoerceProto.to_str(pattern).to_str(); if (idx = this.rindex(pattern)) { start = idx + pattern.length; len = this.size() - start; a = this.slice(0, idx); b = pattern.dup(); c = R(this.to_native().slice(start)); } a || (a = R("")); b || (b = R("")); c || (c = this); return R([a, b, c]); }; String.prototype.rstrip = function() { return this.dup().tap(function(s) { return s.rstrip_bang(); }); }; String.prototype.rstrip_bang = function() { if (!this.to_native().match(/[\s\n\t]+$/)) { return null; } return this.replace(this.to_native().replace(/[\s\n\t]+$/g, '')); }; String.prototype.scan = function(pattern, block) { var fin, index, m, match, match_arr, val; if (block == null) { block = null; } if (!R.Regexp.isRegexp(pattern)) { pattern = CoerceProto.to_str_native(pattern); pattern = R.Regexp.quote(pattern); } index = 0; R['$~'] = null; match_arr = block !== null ? this : []; while (match = this.__native__.slice(index).match(pattern)) { fin = index + match.index + match[0].length; if (match[0].length === 0) { fin += 1; } R['$~'] = new R.MatchData(match, { offset: index, string: this.__native__ }); if (match.length > 1) { val = new R.Array((function() { var _i, _len, _ref1, _results; _ref1 = match.slice(1, match.length); _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { m = _ref1[_i]; _results.push(new R.String(m)); } return _results; })()); } else { val = new R.Array([new R.String(match[0])]); } if (block !== null) { block(val); } else { if (match.length === 1) { val = val.first(); } match_arr.push(val); } index = fin; if (index > this.length) { break; } } if (block !== null) { return this; } else { return new R.Array(match_arr); } }; String.prototype.size = function() { return this.$Integer(this.to_native().length); }; String.prototype.slice = function(index, other) { var len, length, size, start, substr; if (index === null) { throw new R.TypeError["new"](); } index = R(index); size = this.size().to_native(); if (other !== void 0) { if (index.is_regexp != null) { } else { length = CoerceProto.to_int_native(other); start = CoerceProto.to_int_native(index); if (start < 0) { start += size; } if (length < 0) { return null; } if (start < 0 || start > size) { return null; } substr = this.to_native().slice(start, start + length); return new R.String(substr); } } if (index.is_regexp != null) { } else if (index.is_string != null) { if (this.include(index)) { return index.dup(); } else { return null; } } else if (index.is_range != null) { start = CoerceProto.to_int_native(index.begin()); length = CoerceProto.to_int_native(index.end()); if (start < 0) { start += size; } if (length < 0) { length += size; } if (!index.exclude_end()) { length += 1; } if (start === size) { return new R.String(""); } if (start < 0 || start > size) { return null; } if (length > size) { length = size; } length = length - start; if (length < 0) { length = 0; } substr = this.to_native().slice(start, start + length); return new R.String(substr); } else { index = CoerceProto.to_int_native(index); len = this.size().to_native(); if (index < 0) { index += len; } if (index < 0 || index >= this.size()) { return null; } return new R.String(this.to_native()[index]); } }; String.prototype.split = function(pattern, limit) { var ret, str; if (pattern == null) { pattern = " "; } if (!R.Regexp.isRegexp(pattern)) { pattern = CoerceProto.to_str(pattern).to_native(); } ret = this.to_native().split(pattern); ret = R((function() { var _i, _len, _results; _results = []; for (_i = 0, _len = ret.length; _i < _len; _i++) { str = ret[_i]; _results.push(new this.constructor(str)); } return _results; }).call(this)); while (str = ret.last()) { if (!str.empty()) { break; } ret.pop(); } if (pattern === ' ') { ret.delete_if(function(str) { return str.empty(); }); } return ret; }; String.prototype.squeeze_bang = function() { throw new R.NotImplementedError(); }; String.prototype.squeeze = function() { var all, c, chars, i, j, last, len, pattern, tbl; pattern = 1 <= arguments.length ? __slice.call(arguments, 0) : []; tbl = new CharTable(pattern); chars = this.to_native().split(""); len = this.to_native().length; i = 1; j = 0; last = chars[0]; all = pattern.length === 0; while (i < len) { c = chars[i]; if (!(c === last && (all || tbl.include(c)))) { chars[j += 1] = last = c; } i += 1; } if ((j + 1) < len) { chars = chars.slice(0, j + 1 || 9e9); } return new this.constructor(chars.join('')); }; String.prototype.start_with = function() { var needles, w, _i, _len, _ref1; needles = 1 <= arguments.length ? __slice.call(arguments, 0) : []; needles = this.$Array_r(needles).select(function(el) { return (el != null ? el.to_str : void 0) != null; }); _ref1 = needles.iterator(); for (_i = 0, _len = _ref1.length; _i < _len; _i++) { w = _ref1[_i]; if (this.to_native().indexOf(w.to_str().to_native()) === 0) { return true; } } return false; }; String.prototype.strip = function() { return this.dup().tap(function(s) { return s.strip_bang(); }); }; String.prototype.strip_bang = function() { var l, r; l = this.lstrip_bang(); r = this.rstrip_bang(); if (l === null && r === null) { return null; } else { return this; } }; String.prototype.sub = function(pattern, replacement) { return this.dup().tap(function(dup) { return dup.sub_bang(pattern, replacement); }); }; String.prototype.sub_bang = function(pattern, replacement) { var pattern_lit, subbed; if (pattern === null) { throw R.TypeError["new"](); } pattern_lit = String.string_native(pattern); if (pattern_lit !== null) { pattern = new RegExp(R.Regexp.escape(pattern_lit)); } if (!R.Regexp.isRegexp(pattern)) { throw R.TypeError["new"](); } if (pattern.global) { throw "String#sub: " + pattern + " has set the global flag 'g'. " + pattern + "g"; } replacement = CoerceProto.to_str_native(replacement); subbed = this.to_native().replace(pattern, replacement); return this.replace(subbed); }; String.prototype.succ = function() { return this.dup().succ_bang(); }; String.prototype.succ_bang = function() { var c, carry, chars, codes, last_alnum, s, start; if (this.length === 0) { return this.replace(""); } else { codes = (function() { var _i, _len, _ref1, _results; _ref1 = this.to_native().split(""); _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { c = _ref1[_i]; _results.push(c.charCodeAt(0)); } return _results; }).call(this); carry = null; last_alnum = 0; start = codes.length - 1; while (start >= 0) { s = codes[start]; if (String.fromCharCode(s).match(/[a-zA-Z0-9]/) !== null) { carry = 0; if ((48 <= s && s < 57) || (97 <= s && s < 122) || (65 <= s && s < 90)) { codes[start] = codes[start] + 1; } else if (s === 57) { codes[start] = 48; carry = 49; } else if (s === 122) { codes[start] = carry = 97; } else if (s === 90) { codes[start] = carry = 65; } if (carry === 0) { break; } last_alnum = start; } start -= 1; } if (carry === null) { start = codes.length - 1; carry = 1; while (start >= 0) { s = codes[start]; if (s >= 255) { codes[start] = 0; } else { codes[start] = codes[start] + 1; break; } start -= 1; } } chars = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = codes.length; _i < _len; _i++) { c = codes[_i]; _results.push(String.fromCharCode(c)); } return _results; })(); if (start < 0) { chars[last_alnum] = nativeString.fromCharCode(carry, codes[last_alnum]); } return this.replace(chars.join("")); } }; String.prototype.next = String.prototype.succ; String.prototype.next_bang = String.prototype.succ_bang; String.prototype.swapcase = function() { return this.dup().tap(function(s) { return s.swapcase_bang(); }); }; String.prototype.swapcase_bang = function() { if (!this.to_native().match(/[a-zA-Z]/)) { return null; } return this.replace(R(this.__char_natives__()).map(function(c) { if (c.match(/[a-z]/)) { return c.toUpperCase(); } else if (c.match(/[A-Z]/)) { return c.toLowerCase(); } else { return c; } }).join('').to_native()); }; String.prototype.to_a = function() { if (this.empty()) { return this.$Array([]); } else { return this.$Array([this]); } }; String.prototype.valid_float = function() { var number_match; number_match = this.to_native().match(/^([\+\-]?\d[_\d]*)(\.\d*)?([eE][\+\-]?[\d_]+)?$/); return (number_match != null ? number_match[0] : void 0) != null; }; String.prototype.to_f = function() { var number_match, number_string, _ref1; number_match = this.to_native().match(/^([\+\-]?[_\d\.]+)([Ee\+\-\d]+)?/); number_string = (_ref1 = number_match != null ? number_match[0] : void 0) != null ? _ref1 : "0.0"; return this.$Float(Number(number_string.replace(/_/g, ''))); }; String.prototype.to_i = function(base) { var lit; if (base === void 0) { base = 10; } base = CoerceProto.to_int_native(base); if (base < 0 || base > 36 || base === 1) { throw R.ArgumentError["new"](); } lit = this.strip().to_native(); if (!lit.match(/^([\+\-]?)([^\+^\-_]+)/)) { return R(0); } lit = lit.replace(/_/g, ''); return this.$Integer(parseInt(lit, base)); }; String.prototype.to_s = function() { return this; }; String.prototype.to_str = String.prototype.to_s; String.prototype.tr = function(from_str, to_str) { return this.dup().tap(function(dup) { return dup.tr_bang(from_str, to_str); }); }; String.prototype.tr_bang = function(from_str, to_str) { var char, chars, from, from_chars, i, idx, len, out, str, to, to_chars, to_length; chars = this.__char_natives__(); from = new CharTable([from_str]); from_chars = from.include_chars().to_native(); to = new CharTable([to_str]); to_chars = to.include_chars().to_native(); to_length = to_chars.length; out = []; i = 0; len = chars.length; while (i < len) { char = chars[i]; i = i + 1; if (from.include(char)) { idx = from_chars.indexOf(char); if (idx === -1 || idx >= to_length) { idx = to_length - 1; } char = to_chars[idx]; } out.push(char); } str = out.join(''); if (this.equals(str)) { return null; } else { return this.replace(str); } }; String.prototype.tr_s = function() { throw R.NotImplementedError["new"](); }; String.prototype.upcase = function() { return this.dup().tap(function(s) { return s.upcase_bang(); }); }; String.prototype.upcase_bang = function() { if (!this.to_native().match(/[a-z]/)) { return null; } return this.replace(R(this.__char_natives__()).map(function(c) { if (c.match(/[a-z]/)) { return c.toUpperCase(); } else { return c; } }).join('').to_native()); }; String.prototype.upto = function(stop, exclusive, block) { var compare_fn, counter, stop_size; stop = CoerceProto.to_str(stop); exclusive || (exclusive = false); if (block === void 0 && ((exclusive != null ? exclusive.call : void 0) != null)) { block = exclusive; exclusive = false; } if ((stop != null ? stop.is_string : void 0) == null) { throw R.TypeError["new"](); } if (!(block && (block.call != null))) { return RubyJS.Enumerator["new"](this, 'upto', stop, exclusive); } counter = this.dup(); compare_fn = exclusive === false ? 'lteq' : 'lt'; stop_size = stop.size(); while (counter[compare_fn](stop) && !counter.size().gt(stop_size)) { block(counter); counter = counter.succ(); } return this; }; String.prototype.__char_natives__ = function() { return this.__native__.split(''); }; String.__add_default_aliases__(String.prototype); String.prototype.concat = String.prototype['<<']; String.prototype.asciiOnly = String.prototype.ascii_only; String.prototype.caseCompare = String.prototype.case_compare; String.prototype.eachChar = String.prototype.each_char; String.prototype.eachLine = String.prototype.each_line; String.prototype.endWith = String.prototype.end_with; String.prototype.startWith = String.prototype.start_with; String.prototype.trS = String.prototype.tr_s; return String; })(RubyJS.Object); CharTable = (function() { function CharTable(patterns) { var arr, v, w, _i, _len, _ref1; this.patterns = patterns; this.incl = null; this.excl = null; _ref1 = this.patterns; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { w = _ref1[_i]; v = CoerceProto.to_str(w).to_native(); if (v.length === 0) { } else if (v[0] === '^' && v.length > 1) { arr = this.__char_table__(v.slice(1)); this.excl = this.excl ? this.excl['&'](arr) : R(arr); } else { arr = this.__char_table__(v); this.incl = this.incl ? this.incl['&'](arr) : R(arr); } } } CharTable.prototype.include_chars = function() { return this.incl || new R.Array([]); }; CharTable.prototype.exclude_chars = function() { return this.excl || new R.Array([]); }; CharTable.prototype.exclude = function(chr) { return !this.include(chr); }; CharTable.prototype.include = function(chr) { if (this.incl && this.excl) { return this.incl.include(chr) && !this.excl.include(chr); } else if (this.incl) { return this.incl.include(chr); } else if (this.excl) { return !this.excl.include(chr); } else { return false; } }; CharTable.prototype.__char_table__ = function(str) { var arr, m, s, _i, _len; arr = []; if (m = str.match(/[^\\]\-./g)) { for (_i = 0, _len = m.length; _i < _len; _i++) { s = m[_i]; arr = arr.concat(this.__char_range__(s[0], s[2])); } } arr = arr.concat(str.replace(/[^\\]\-./g, '').split("")); return arr; }; CharTable.prototype.__char_range__ = function(a, b) { var arr, counter; arr = []; a = R(a); if (!a['<='](b)) { throw R.ArgumentError["new"](); } counter = 0; while (a['<='](b)) { counter++; arr.push(a.to_native()); a = a.succ(); if (counter === 10000) { throw R.ArgumentError["new"]("ERROR: " + a + " " + b); } } return arr; }; return CharTable; })(); RStrProto = RubyJS.String.prototype; RubyJS.Regexp = (function(_super) { __extends(Regexp, _super); Regexp.prototype.IGNORECASE = 1; Regexp.prototype.EXTENDED = 2; Regexp.prototype.MULTILINE = 4; function Regexp(__native__) { this.__native__ = __native__; } Regexp["new"] = function(arg) { if (typeof arg === 'string') { arg = this.__compile__(arg); } else if (RubyJS.Regexp.isRegexp(arg)) { } else if (arg.is_regexp != null) { arg = arg.to_native(); } else { arg = this.__compile__(CoerceProto.to_str_native(arg)); } return new RubyJS.Regexp(arg); }; Regexp.compile = Regexp["new"]; Regexp.try_convert = function(obj) { if (obj === null) { return null; } else if (this.isRegexp(obj)) { return new R.Regexp(obj); } else if (obj.to_regexp != null) { return obj.to_regexp(); } else { return null; } }; Regexp.isRegexp = function(obj) { return _toString_.call(obj) === '[object RegExp]' || (obj.is_regexp != null); }; Regexp.prototype.is_regexp = function() { return true; }; Regexp.prototype.to_native = function() { return this.__native__; }; Regexp.prototype.inspect = function() { var src; src = this.source().to_native(); return R("/" + src + "/" + (this.__flags__())); }; Regexp.prototype['=='] = function(other) { other = R(other); return (other.to_native().source === this.to_native().source) && (other.casefold() === this.casefold()); }; Regexp.prototype['==='] = function(other) { return this.match(other) !== null; }; Regexp.prototype['=~'] = function(str, offset) { var matches; matches = this.match(str, offset); return matches != null ? matches.begin(0) : void 0; }; Regexp.prototype.casefold = function() { return this.to_native().ignoreCase; }; Regexp.prototype.encoding = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.prototype.eql = function() { return this['=='].apply(this, arguments); }; Regexp.prototype.fixed_encoding = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.prototype.hash = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.prototype.match = function(str, offset) { var block, matches, opts, result; block = this.__extract_block(_slice_.call(arguments)); if (str === null) { R['$~'] = null; } else { str = CoerceProto.to_str_native(str); opts = { string: str, regexp: this }; if (offset) { opts.offset = offset; str = str.slice(offset); } if (matches = str.match(this.to_native())) { R['$~'] = new R.MatchData(matches, opts); } else { R['$~'] = null; } } result = R['$~']; if (block) { if (result) { return block(result); } else { return new R.Array([]); } } else { return result; } }; Regexp.prototype.quote = function(pattern) { return R.Regexp.quote(pattern); }; Regexp.prototype.source = function() { return R(this.to_native().source); }; Regexp.prototype.to_s = function() { return R("(" + (this.source()) + ")"); }; Regexp.last_match = function(n) { if (n && R['$~']) { return R['$~'][n]; } else { return R['$~']; } }; Regexp.quote = function(pattern) { return this.escape(pattern); }; Regexp.escape = function(pattern) { pattern = pattern + ''; return pattern.replace(/([.?*+^$[\](){}|-])/g, "\\$1").replace(/[\f]/g, '\\f').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r').replace(/[\t]/g, '\\t').replace(/[\s]/g, '\\ '); }; Regexp.union = function() { var arg, args, first_arg, sources; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (args.length === 0) { return R(/(?!)/); } first_arg = R(args[0]); if ((first_arg.is_array != null) && args.length === 1) { args = first_arg; } sources = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = args.length; _i < _len; _i++) { arg = args[_i]; arg = R(arg); if (arg.is_regexp != null) { _results.push(arg.to_s()); } else { _results.push(CoerceProto.to_str(arg)); } } return _results; })(); return new RubyJS.Regexp(new nativeRegExp(sources.join('|'))); }; Regexp.__compile__ = function(arg) { try { return new nativeRegExp(arg); } catch (error) { throw R.RegexpError["new"](); } }; Regexp.prototype.__flags__ = function() { if (this.casefold()) { return 'i'; } else { return ''; } }; Regexp.prototype.names = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.prototype.named_captures = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.prototype.options = function() { throw RubyJS.NotSupportedError["new"](); }; Regexp.__add_default_aliases__(Regexp.prototype); Regexp.prototype.fixedEncoding = Regexp.prototype.fixed_encoding; return Regexp; })(RubyJS.Object); RubyJS.Numeric = (function(_super) { __extends(Numeric, _super); function Numeric() { return Numeric.__super__.constructor.apply(this, arguments); } Numeric.isNumeric = function(obj) { if (typeof obj === 'number') { return true; } if (typeof obj !== 'object') { return false; } if (obj === null) { return false; } return (obj.valueOf != null) && typeof obj.valueOf() === 'number'; }; Numeric.try_convert = function(obj) { if (!this.isNumeric(obj)) { return null; } return this["new"](obj); }; Numeric["new"] = function(value) { if (value % 1 === 0) { return new R.Fixnum(value); } else { return new R.Float(value); } }; Numeric.typecast = function(value) { if (value % 1 === 0) { return new R.Fixnum(value); } else { return new R.Float(value); } }; Numeric.prototype.is_numeric = function() { return true; }; Numeric.prototype['<=>'] = function(other) { if (this === other) { return 0; } else { return null; } }; Numeric.prototype.abs = function() { if (this['<'](0)) { return this.uminus(); } else { return this; } }; Numeric.prototype.abs2 = function() { if (typeof this.nan === "function" ? this.nan() : void 0) { return this; } return this.abs()['**'](2); }; Numeric.prototype.ceil = function() { return this.to_f().ceil(); }; Numeric.prototype.coerce = function(other) { if (other === null || other === false || other === void 0) { throw RubyJS.TypeError["new"](); } other = this.box(other); if (other.is_string != null) { return this.$Array([this.$Float(other), this.to_f()]); } else if (other.constructor.prototype === this.constructor.prototype) { return this.$Array([other, this]); } else if (other.is_float != null) { return this.$Array([other, this.to_f()]); } else if (other.is_fixnum != null) { return this.$Array([other, this]); } else if (other.is_numeric != null) { return this.$Array([other.to_f(), this.to_f()]); } else { throw RubyJS.TypeError["new"](); } }; Numeric.prototype.div = function(other) { other = this.box(other); if (other.to_int == null) { throw RubyJS.TypeError["new"](); } if (other.zero()) { throw new Error("ZeroDivisionError"); } return this.divide(other).floor(); }; Numeric.prototype.divmod = function(other) { var modulus, quotient; quotient = this.div(other).floor(); modulus = this.minus(quotient.multiply(other)); return new R.Array([quotient, modulus]); }; Numeric.prototype.eql = function(other) { other = this.box(other); if (!other) { return false; } if (this.__proto__ !== other.__proto__) { return false; } if (this['=='](other)) { return true; } else { return false; } }; Numeric.prototype.inspect = function() { return "" + this.to_native(); }; Numeric.prototype.fdiv = function(other) { other = CoerceProto.to_num_native(other); return this.to_f()['/'](other); }; Numeric.prototype.floor = function() { return this.to_f().floor(); }; Numeric.prototype.magnitude = function() { return this.abs(); }; Numeric.prototype.modulo = function(other) { other = this.box(other); return this['-'](other['*'](this.div(other))); }; Numeric.prototype.nonzero = function() { if (this.zero()) { return null; } else { return this; } }; Numeric.prototype.quo = function(other) { var arr; other = this.box(other); if (other.zero()) { throw new Error("ZeroDivisionError"); } arr = this.coerce(other); return this['/'](arr.first()); }; Numeric.prototype.rect = function() { if (arguments.length > 0) { throw R.ArgumentError["new"](); } return new R.Array([this, new R.Fixnum(0)]); }; Numeric.prototype.rectangular = Numeric.prototype.rect; Numeric.prototype.remainder = function(other) { var mod; other = this.box(other); mod = this['%'](other); if (!mod['=='](0) && ((this['<'](0) && other['>'](0)) || (this['>'](0) && other['<'](0)))) { return mod['-'](other); } else { return mod; } }; Numeric.prototype.round = function(n) { return this.to_f().round(n); }; Numeric.prototype.step = function(limit, step, block) { var d, i, n, value; if (step == null) { step = 1; } limit = this.box(limit); if ((block != null ? block.call : void 0) != null) { } else { block = step; step = 1; } step = this.box(step); if ((block != null ? block.call : void 0) == null) { return this.to_enum('step', limit, step); } if (step.equals(0)) { throw new R.ArgumentError("ArgumentError"); } value = this; if ((value.is_float != null) || (limit.is_float != null) || (step.is_float != null)) { n = (limit.to_f().minus(value)).divide(step); i = R(0).to_f(); if (step.gt(0)) { while (i.lteq(n)) { d = i.multiply(step).plus(value); if (limit.lt(d)) { d = limit; } block(d); i = i.plus(1); } } else { while (i.lteq(n)) { d = i.multiply(step).plus(value); if (limit.gt(d)) { d = limit; } block(d); i = i.plus(1); } } } else { if (step.gt(0)) { while (!value.gt(limit)) { block(value); value = value.plus(step); } } else { while (!value.lt(limit)) { block(value); value = value.plus(step); } } } return this; }; Numeric.prototype.to_int = function() { return this.to_i(); }; Numeric.prototype.truncate = function() { return this.to_f().truncate(); }; Numeric.prototype.uminus = function() { return this.multiply(-1); }; Numeric.prototype.zero = function() { return this['=='](0); }; return Numeric; })(RubyJS.Object); RubyJS.Integer = (function(_super) { __extends(Integer, _super); function Integer() { return Integer.__super__.constructor.apply(this, arguments); } Integer["new"] = function(value) { return new Integer(value); }; Integer.isInteger = function(obj) { return this.isNumeric(obj) && (obj % 1 === 0); }; Integer.prototype.is_integer = function() { return true; }; Integer.prototype.unbox = function() { return this.to_native(); }; Integer.prototype.chr = function() { return new R.String(String.fromCharCode(this.to_native())); }; Integer.prototype.denominator = function() { return new R.Fixnum(1); }; Integer.prototype.upto = function(stop, block) { var idx; stop = R(stop); if ((stop != null ? stop.to_int : void 0) == null) { throw RubyJS.ArgumentError["new"](); } if (!(block && (block.call != null))) { return RubyJS.Enumerator["new"](this, 'upto', stop); } stop = stop.floor().to_native(); if (!(this.to_native() <= stop)) { return this; } idx = this.to_native(); while (idx <= stop) { block(new R.Fixnum(idx)); idx += 1; } return this; }; Integer.prototype.downto = function(stop, block) { var idx; stop = R(stop); if ((stop != null ? stop.to_int : void 0) == null) { throw RubyJS.ArgumentError["new"](); } if (!(block && (block.call != null))) { return RubyJS.Enumerator["new"](this, 'downto', stop); } stop = Math.ceil(stop.to_native()); if (!(this.to_native() >= stop)) { return this; } idx = this.to_native(); while (idx >= stop) { block(new R.Fixnum(idx)); idx = idx - 1; } return this; }; Integer.prototype.even = function() { return this.to_native() % 2 === 0; }; Integer.prototype.gcd = function(other) { var a, b, t; other = this.box(other); this.__ensure_args_length(arguments, 1); this.__ensure_integer__(other); a = this.to_native(); b = other.to_native(); t = null; while (b !== 0) { t = b; b = a % b; a = t; } return new R.Fixnum(a).numerator(); }; Integer.prototype.gcdlcm = function(other) { other = this.box(other); this.__ensure_args_length(arguments, 1); this.__ensure_integer__(other); return new R.Array([this.gcd(other), this.lcm(other)]); }; Integer.prototype.lcm = function(other) { var lcm; other = R(other); this.__ensure_args_length(arguments, 1); this.__ensure_integer__(other); lcm = new R.Fixnum(this.to_native() * other.to_native() / this.gcd(other)); return lcm.numerator(); }; Integer.prototype.numerator = function() { if (this.lt(0)) { return this.$Integer(this.to_native() * -1); } else { return this; } }; Integer.prototype.odd = function() { return !this.even(); }; Integer.prototype.ord = function() { return this; }; Integer.prototype.next = function() { return this.plus(1); }; Integer.prototype.pred = function() { return this.minus(1); }; Integer.prototype.round = function(n) { var multiplier; if (n === void 0) { return this; } n = CoerceProto.to_int_native(n); if (n > 0) { return this.to_f(); } else if (n === 0) { return this; } else { multiplier = Math.pow(10, n); return new R.Fixnum(Math.round(this.to_native() * multiplier) / multiplier); } }; Integer.prototype.succ = Integer.prototype.next; Integer.prototype.times = function(block) { var idx, len; if ((block != null ? block.call : void 0) == null) { return this.to_enum('times'); } len = this.to_native(); if (len > 0) { idx = 0; while (idx < len) { block(new R.Fixnum(idx)); idx = idx + 1; } return this; } else { return this; } }; Integer.prototype.to_i = function() { return this; }; Integer.prototype.toString = function() { return "" + (this.to_native()); }; Integer.prototype.__ensure_integer__ = function(other) { if ((other != null ? other.is_integer : void 0) == null) { throw RubyJS.TypeError["new"](); } }; Integer.prototype.to_int = Integer.prototype.to_i; Integer.prototype.truncate = Integer.prototype.to_i; return Integer; })(RubyJS.Numeric); RubyJS.Fixnum = (function(_super) { __extends(Fixnum, _super); Fixnum.include(RubyJS.Comparable); function Fixnum(__native__) { this.__native__ = __native__; } Fixnum["new"] = function(val) { return new RubyJS.Fixnum(val); }; Fixnum.try_convert = function(obj) { obj = R(obj); if (obj.to_int == null) { throw RubyJS.TypeError["new"](); } return obj; }; Fixnum.__cache_fixnums__ = function(from, to) { var i, _i, _results; if (from == null) { from = -1; } if (to == null) { to = 256; } _results = []; for (i = _i = from; from <= to ? _i <= to : _i >= to; i = from <= to ? ++_i : --_i) { _results.push(this.__memoized_fixnums__[i] = new R.Fixnum(i)); } return _results; }; Fixnum.prototype.is_fixnum = function() { return true; }; Fixnum.prototype.to_native = function() { return this.__native__; }; Fixnum.prototype.valueOf = Fixnum.prototype.to_native; Fixnum.prototype.unbox = Fixnum.prototype.to_native; Fixnum.prototype.dup = function() { return Fixnum["new"](this.to_native()); }; Fixnum.prototype['=='] = function(other) { if (!(this.box(other).is_fixnum != null)) { return other['=='](this); } else { return this['<=>'](other) === 0; } }; Fixnum.prototype['==='] = Fixnum.prototype['==']; Fixnum.prototype['<=>'] = function(other) { if (typeof other !== 'number') { other = R(other); if (other.is_numeric == null) { return null; } if (other.to_int == null) { throw RubyJS.TypeError["new"](); } other = other.to_native(); } if (this.to_native() < other) { return -1; } else if (this.to_native() > other) { return 1; } else { return 0; } }; Fixnum.prototype['+'] = function(other) { return RubyJS.Numeric.typecast(this.to_native() + CoerceProto.to_num_native(other)); }; Fixnum.prototype['-'] = function(other) { return RubyJS.Numeric.typecast(this.to_native() - CoerceProto.to_num_native(other)); }; Fixnum.prototype['/'] = function(other) { var val; other = Fixnum.try_convert(other); if ((other.is_float != null) && other.zero()) { if (this.to_native() > 0) { return R('Infinity'); } else { return R('-Infinity'); } } else if (+other === 0) { throw R.ZeroDivisionError["new"](); } else { val = RubyJS.Numeric.typecast(this.to_native() / other.to_native()); if (other.is_float != null) { return val; } else { return val.floor(); } } }; Fixnum.prototype['*'] = function(other) { return RubyJS.Numeric.typecast(this.to_native() * CoerceProto.to_num_native(other)); }; Fixnum.prototype['**'] = function(other) { var val; other = this.box(other); val = this.box(Math.pow(this.to_native(), other.unbox())); if (other.is_float != null) { return val.to_f(); } else { return val.to_i(); } }; Fixnum.prototype['%'] = function(other) { var division, fixnum, is_float, val; is_float = this.box(other).is_float != null; fixnum = Fixnum.try_convert(other); if (fixnum.zero()) { throw R.ZeroDivisionError["new"](); } fixnum = fixnum.to_int(); division = this['/'](fixnum); val = this.minus(division.multiply(fixnum)); if (is_float) { return val.to_f(); } else { return val.to_i(); } }; Fixnum.prototype.fdiv = function(other) { other = R(other); if (other.is_numeric == null) { throw RubyJS.TypeError["new"](); } this.__ensure_args_length(arguments, 1); return this.to_f().divide(other.to_f()); }; Fixnum.prototype.object_id = function() { return this.__native__ * 2 + 1; }; Fixnum.prototype.to_f = function() { return this.$Float(this.to_native()); }; Fixnum.prototype.to_s = function(base) { if (base == null) { base = 10; } base = this.box(base); if (base.lt(2) || base.gt(36)) { throw RubyJS.ArgumentError["new"](); } return this.box("" + (this.to_native().toString(base.unbox()))); }; Fixnum.__add_default_aliases__(Fixnum.prototype); return Fixnum; })(RubyJS.Integer); RubyJS.Float = (function(_super) { __extends(Float, _super); Float.include(RubyJS.Comparable); Float.INFINITY = 1.0 / 0.0; Float.NAN = 0.0 / 0.0; Float.DIG = 15; Float.EPSILON = 0.0000000000000002220446049250313080847263336181640625; Float.MANT_DIG = 53; Float.MAX_10_EXP = 308; Float.MIN_10_EXP = -307; Float.MAX_EXP = 1024; Float.MIN_EXP = -1021; Float.MAX = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368; Float.MANT_DIG = 53; Float.MIN = 2.225073858507201383090232717332404064219215980462331830553327416887204434813918195854283159012511020564067339731035811005152434161553460108856012385377718821130777993532002330479610147442583636071921565046942503734208375250806650616658158948720491179968591639648500635908770118304874799780887753749949451580451605050915399856582470818645113537935804992115981085766051992433352114352390148795699609591288891602992641511063466313393663477586513029371762047325631781485664350872122828637642044846811407613911477062801689853244110024161447421618567166150540154285084716752901903161322778896729707373123334086988983175067838846926092773977972858659654941091369095406136467568702398678315290680984617210924625396728515625e-308; Float.RADIX = 2; Float["new"] = function(f) { return new R.Float(f); }; function Float(__native__) { this.__native__ = __native__; } Float.prototype.is_float = function() { return true; }; Float.prototype.toString = function() { return this.to_native().toString(); }; Float.prototype.valueOf = function() { return this.__native__; }; Float.prototype.to_native = function() { return this.__native__; }; Float.prototype.unbox = Float.prototype.to_native; Float.isFloat = function(obj) { return RubyJS.Numeric.isNumeric(obj) && !RubyJS.Integer.isInteger(obj); }; Float.prototype.arg = function() { if (this.nan()) { return this; } else if (this.lt(0.0)) { return this.$Float(Math.PI); } else { return this.$Float(0); } }; Float.prototype.ceil = function() { return new RubyJS.Fixnum(Math.ceil(this.to_native())); }; Float.prototype.inspect = function() { return this.to_s(); }; Float.prototype['<=>'] = function(other) { if (!(this.box(other).is_numeric != null)) { return null; } other = CoerceProto.to_num_native(other); if (this.to_native() === other) { return 0; } if (this.to_native() < other) { return -1; } if (this.to_native() > other) { return 1; } }; Float.prototype.dup = function() { return Float["new"](this.to_native()); }; Float.prototype['=='] = function(other) { other = this.box(other); return this.to_native() === other.to_native(); }; Float.prototype['+'] = function(other) { return new Float(this.to_native() + CoerceProto.to_num_native(other)); }; Float.prototype['-'] = function(other) { return new Float(this.to_native() - CoerceProto.to_num_native(other)); }; Float.prototype['*'] = function(other) { return new Float(this.to_native() * CoerceProto.to_num_native(other)); }; Float.prototype['/'] = function(other) { return new Float(this.to_native() / CoerceProto.to_num_native(other)); }; Float.prototype['**'] = function(other) { return new Float(Math.pow(this.to_native(), CoerceProto.to_num_native(other)) + 0); }; Float.prototype['%'] = function(other) { var div, inf, val; other = this.box(other); if (other.equals(0)) { throw new Error("ZeroDivisionError"); } if (!this.finite()) { return this.box(Float.NAN).to_f(); } if (inf = typeof other.infinite === "function" ? other.infinite() : void 0) { if (inf === -1) { return other; } if (inf === 1) { return this; } } div = this['/'](other).floor(); val = this.to_native() - (div.to_native() * other.to_native()); return new Float(val); }; Float.prototype.eql = function(other) { other = this.box(other); if (other.is_float == null) { return false; } return this.equals(other); }; Float.prototype.finite = function() { return !(this.infinite() || this.nan()); }; Float.prototype.infinite = function() { if (this.to_native() === Float.INFINITY) { return 1; } else if (this.to_native() === -Float.INFINITY) { return -1; } else { return null; } }; Float.prototype.nan = function() { return isNaN(this.to_native()); }; Float.prototype.to_f = function() { return this.dup(); }; Float.prototype.to_i = function() { if (this.to_native() < 0) { return this.ceil(); } else { return this.floor(); } }; Float.prototype.floor = function() { return new R.Fixnum(Math.floor(this.__native__)); }; Float.prototype.quo = function(other) { this.__ensure_args_length(arguments, 1); other = this.box(other); return this.divide(other); }; Float.prototype.round = function(n) { var multiplier, rounded; if (n == null) { n = 0; } n = CoerceProto.to_int_native(n); if (this.infinite()) { throw new TypeError("FloatDomainError"); } if (this.nan()) { throw new TypeError("RangeError"); } if (n === 0) { return new RubyJS.Fixnum(Math.round(this.to_native())); } multiplier = Math.pow(10, n); rounded = Math.round(this.to_native() * multiplier) / multiplier; if (n > 0) { return new RubyJS.Float(rounded); } else { return new RubyJS.Fixnum(rounded); } }; Float.prototype.to_s = function() { var inf, v; v = "" + this.to_native(); if (this.nan()) { v = "NaN"; } else if (inf = this.infinite()) { if (inf === -1) { v = "-Infinity"; } if (inf === 1) { v = "Infinity"; } } else if (v.indexOf('.') < 0) { v += ".0"; } return this.$String(v); }; Float.prototype.angle = Float.prototype.arg; Float.prototype.fdiv = Float.prototype.quo; Float.prototype.magnitude = Float.prototype.abs; Float.prototype.phase = Float.prototype.arg; Float.prototype.to_int = Float.prototype.to_i; Float.prototype.truncate = Float.prototype.to_i; Float.prototype['==='] = Float.prototype['==']; Float.__add_default_aliases__(Float.prototype); return Float; })(RubyJS.Numeric); RubyJS.Time = (function(_super) { __extends(Time, _super); Time.include(RubyJS.Comparable); Time["new"] = function() { return new RubyJS.Time(); }; function Time() {} return Time; })(RubyJS.Object); }).call(this);