Comparing version
@@ -14,2 +14,3 @@ 'use strict'; | ||
this.putc = putc; | ||
this.puts = puts; | ||
@@ -20,14 +21,36 @@ }; | ||
function putc(arg) { | ||
if (arguments.length !== 1) { | ||
throw 'ArgumentError: wrong number of arguments (' + arguments.length + ' for 1)'; | ||
} | ||
if (!((0, _lodash.isNumber)(arg) || (0, _lodash.isString)(arg))) { | ||
throw 'no implicit conversion of ' + typeof arg + ' into Integer (TypeError)'; | ||
} | ||
var output = undefined; | ||
if ((0, _lodash.isString)(arg)) { | ||
output = arg.slice(0, 1); | ||
} else { | ||
output = String.fromCharCode(arg); | ||
} | ||
process.stdout.write(output); | ||
return arg; | ||
} | ||
function puts() { | ||
(0, _lodash.each)(arguments, function (arg) { | ||
if ((0, _lodash.isString)(arg) || (0, _lodash.isNumber)(arg) || (0, _lodash.isBoolean)(arg)) { | ||
console.log(String(arg)); | ||
_printWithNewLine(String(arg)); | ||
} else if ((0, _lodash.isNull)(arg) || (0, _lodash.isUndefined)(arg)) { | ||
console.log(''); | ||
_printWithNewLine(''); | ||
} else if ((0, _lodash.isRegExp)(arg)) { | ||
var stringifiedRegEx = _convertRegexToString(arg); | ||
console.log(stringifiedRegEx); | ||
_printWithNewLine(stringifiedRegEx); | ||
} else if (arg instanceof Error) { | ||
var stringifiedError = _convertErrorToString(arg); | ||
console.log(stringifiedError); | ||
_printWithNewLine(stringifiedError); | ||
} else if ((0, _lodash.isArray)(arg)) { | ||
@@ -38,3 +61,3 @@ (0, _lodash.each)(arg, function (element) { | ||
} else if (!(0, _lodash.isPlainObject)(arg) && (0, _lodash.isObject)(arg)) { | ||
console.log('#<' + arg.constructor.name + '>'); | ||
_printWithNewLine('#<' + arg.constructor.name + '>'); | ||
} else { | ||
@@ -46,2 +69,6 @@ console.log(arg); | ||
function _printWithNewLine(arg) { | ||
process.stdout.write(arg + '\n'); | ||
} | ||
function _convertRegexToString(regex) { | ||
@@ -48,0 +75,0 @@ var str = String(regex); |
{ | ||
"name": "ruby", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Helper methods from ruby ported to Node.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,6 +16,15 @@ # Ruby-Node | ||
```js | ||
let r = require('ruby'); | ||
import { w, puts } from 'ruby'; | ||
let words = r.w('I am not throwing away my shot!'); | ||
let words = w('I am not throwing away my shot!'); | ||
words; // ['I', 'am', 'not', 'throwing', 'away', 'my', 'shot!'] | ||
puts(words); | ||
// I | ||
// am | ||
// not | ||
// throwing | ||
// away | ||
// my | ||
// shot! | ||
``` | ||
@@ -22,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
270300
53.85%195
11.43%38
31.03%