forked from samuel-velazquez/gpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.html
403 lines (255 loc) · 12.9 KB
/
string.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!DOCTYPE html>
<html>
<head>
<title>String</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" media="all" href="assets/css/style.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.4/semantic.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/styles/tomorrow-night.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.4/semantic.min.js"></script>
<script src="assets/js/javascript.js"></script>
</head>
<body>
<div class="ui left push vertical inverted sidebar menu">
<a class="item menu-link" href="index.html">
Index
</a>
<a class="item menu-link" href="integer.html">
Integer
</a>
<a class="item menu-link" href="percent_strings.html">
Percent Strings
</a>
<a class="item menu-link" href="stdout.html">
Stdout
</a>
<a class="item menu-link" href="string.html">
String
</a>
</div>
<div class='pusher'>
<div id='menu-buttons' class='ui fixed top sticky'>
<div class='ui basic button icon' id='menu-button'>
<i class='icon sidebar'></i>
</div>
<a href='https://github.com/crookedneighbor/ruby-node/blob/master/src/string.js' class='ui basic button icon' data-content="View Source Code">
<i class='icon code'></i>
</a>
</div>
<div id="background" class="hljs"></div>
<div id="container" class="ui container">
<div class="ui middle aligned two column grid">
<h2 class="ui icon header center aligned column">
<i class="write icon"></i>
String
<div class="sub header">All strings attached!</div>
</h2>
<div class='column'></div>
</div>
<div class="sections">
<div id="Methods
" class="section-1 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#Methods
">
<i class="linkify icon"></i>
</a>
<h1 id="methods">Methods</h1>
<ul>
<li><a href="#chars">chars</a></li>
<li><a href="#downcase">downcase</a></li>
<li><a href="#empty">empty</a></li>
<li><a href="#reverse">reverse</a></li>
<li><a href="#upcase">upcase</a></li>
</ul>
<p>These can be called through the str object on ruby:</p>
<pre><code class="lang-js">ruby.str.downcase(<span class="hljs-string">'hEllO'</span>); <span class="hljs-comment">// hello</span>
</code></pre>
<p>Or, if you call the <code>add_methods_to_string_prototype</code> method, you can call each applicable method as a property on any string.</p>
<pre><code class="lang-js">ruby = <span class="hljs-built_in">require</span>(<span class="hljs-string">'ruby'</span>);
ruby.add_methods_to_string_prototype();
<span class="hljs-string">'hEllO'</span>.downcase; <span class="hljs-comment">// hello</span>
</code></pre>
<p>The examples below will always use the prototype version, unless otherwise specified.</p>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">_String</span> </span>{
constructor () {
<span class="hljs-keyword">this</span>.chars = chars;
<span class="hljs-keyword">this</span>.downcase = downcase;
<span class="hljs-keyword">this</span>.empty = empty;
<span class="hljs-keyword">this</span>.empty_questionmark = <span class="hljs-keyword">this</span>.empty;
<span class="hljs-keyword">this</span>.reverse = reverse;
<span class="hljs-keyword">this</span>.upcase = upcase;
}</pre></div></div>
</div>
<div id="new
Creates a new string.
Only available on `ruby.str`, not as a method on an instance of `String`.
```js" class="section-2 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#new
Creates a new string.
Only available on `ruby.str`, not as a method on an instance of `String`.
```js">
<i class="linkify icon"></i>
</a>
<h1 id="new">new</h1>
<p>Creates a new string.</p>
<p>Only available on <code>ruby.str</code>, not as a method on an instance of <code>String</code>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> new_string = ruby.str.new(<span class="hljs-string">'abc'</span>);
new_string; <span class="hljs-comment">// 'abc'</span>
</code></pre>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre> <span class="hljs-keyword">new</span> (str) {
<span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${str}</span>`</span>;
}</pre></div></div>
</div>
<div id="chars
Returns the characters of the string in an array.
```js
let chars = 'abc'.chars;
chars; // ['a', 'b', 'c']
```" class="section-4 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#chars
Returns the characters of the string in an array.
```js
let chars = 'abc'.chars;
chars; // ['a', 'b', 'c']
```">
<i class="linkify icon"></i>
</a>
<h1 id="chars">chars</h1>
<p>Returns the characters of the string in an array.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> chars = <span class="hljs-string">'abc'</span>.chars;
chars; <span class="hljs-comment">// ['a', 'b', 'c']</span>
</code></pre>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chars</span>(<span class="hljs-params">str</span>) </span>{
str = str || <span class="hljs-keyword">this</span>;
<span class="hljs-keyword">return</span> str.split(<span class="hljs-string">''</span>);
}</pre></div></div>
</div>
<div id="downcase
Returns the string with all lowercase letters.
```js
let str = 'hEllO'.downcase;
str; // 'hello'
```" class="section-5 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#downcase
Returns the string with all lowercase letters.
```js
let str = 'hEllO'.downcase;
str; // 'hello'
```">
<i class="linkify icon"></i>
</a>
<h1 id="downcase">downcase</h1>
<p>Returns the string with all lowercase letters.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> str = <span class="hljs-string">'hEllO'</span>.downcase;
str; <span class="hljs-comment">// 'hello'</span>
</code></pre>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">downcase</span>(<span class="hljs-params">str</span>) </span>{
str = str || <span class="hljs-keyword">this</span>;
<span class="hljs-keyword">return</span> str.toLowerCase();
}</pre></div></div>
</div>
<div id="empty
Returns true if the string is empty and false if it is not.
```js
'hello'.empty; // false
' '.empty; // false
''.empty; // true
```
`empty_questionmark` is an alias for `empty`." class="section-6 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#empty
Returns true if the string is empty and false if it is not.
```js
'hello'.empty; // false
' '.empty; // false
''.empty; // true
```
`empty_questionmark` is an alias for `empty`.">
<i class="linkify icon"></i>
</a>
<h1 id="empty">empty</h1>
<p>Returns true if the string is empty and false if it is not.</p>
<pre><code class="lang-js"><span class="hljs-string">'hello'</span>.empty; <span class="hljs-comment">// false</span>
<span class="hljs-string">' '</span>.empty; <span class="hljs-comment">// false</span>
<span class="hljs-string">''</span>.empty; <span class="hljs-comment">// true</span>
</code></pre>
<p><code>empty_questionmark</code> is an alias for <code>empty</code>.</p>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">empty</span>(<span class="hljs-params">str</span>) </span>{
<span class="hljs-keyword">if</span> (str === <span class="hljs-literal">undefined</span>) { <span class="hljs-comment">// eslint-disable-line no-undefined</span>
str = <span class="hljs-keyword">this</span>;
}
<span class="hljs-keyword">return</span> str.length === <span class="hljs-number">0</span>;
}</pre></div></div>
</div>
<div id="reverse
Returns the string in reverse order.
```js
let str = 'stressed'.reverse;
str; // 'desserts'
```" class="section-7 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#reverse
Returns the string in reverse order.
```js
let str = 'stressed'.reverse;
str; // 'desserts'
```">
<i class="linkify icon"></i>
</a>
<h1 id="reverse">reverse</h1>
<p>Returns the string in reverse order.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> str = <span class="hljs-string">'stressed'</span>.reverse;
str; <span class="hljs-comment">// 'desserts'</span>
</code></pre>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reverse</span>(<span class="hljs-params">str</span>) </span>{
str = str || <span class="hljs-keyword">this</span>;
<span class="hljs-keyword">let</span> parts = str.split(<span class="hljs-string">''</span>);
<span class="hljs-keyword">let</span> reversedParts = parts.reverse();
<span class="hljs-keyword">let</span> reversed = reversedParts.join(<span class="hljs-string">''</span>);
<span class="hljs-keyword">return</span> reversed;
}</pre></div></div>
</div>
<div id="upcase
Returns the string with all uppercase letters.
```js
let str = 'hEllO'.upcase;
str; // 'HELLO'
```" class="section-8 ui middle aligned two column grid">
<div class="annotation column">
<a class='section-link' href="#upcase
Returns the string with all uppercase letters.
```js
let str = 'hEllO'.upcase;
str; // 'HELLO'
```">
<i class="linkify icon"></i>
</a>
<h1 id="upcase">upcase</h1>
<p>Returns the string with all uppercase letters.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> str = <span class="hljs-string">'hEllO'</span>.upcase;
str; <span class="hljs-comment">// 'HELLO'</span>
</code></pre>
</div>
<div class="content column hljs javascript"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">upcase</span>(<span class="hljs-params">str</span>) </span>{
str = str || <span class="hljs-keyword">this</span>;
<span class="hljs-keyword">return</span> str.toUpperCase();
}</pre></div></div>
</div>
</div>
</div>
</div>
</body>
</html>