These can be called through the str object on ruby:
Or, if you call the add_methods_to_string_prototype
method, you can call each applicable method as a property on any string.
The examples below will always use the prototype version, unless otherwise specified.
export default class _String {
constructor () {
this.chars = chars;
this.downcase = downcase;
this.empty = empty;
this.empty_questionmark = this.empty;
this.reverse = reverse;
this.upcase = upcase;
}
new (str) {
return `${str}`;
}
function chars(str) {
str = str || this;
return str.split('');
}
function downcase(str) {
str = str || this;
return str.toLowerCase();
}
Returns true if the string is empty and false if it is not.
empty_questionmark
is an alias for empty
.
function empty(str) {
if (str === undefined) { // eslint-disable-line no-undefined
str = this;
}
return str.length === 0;
}
function reverse(str) {
str = str || this;
let parts = str.split('');
let reversedParts = parts.reverse();
let reversed = reversedParts.join('');
return reversed;
}