@@ -70,6 +70,10 @@ def <=>(other)
70
70
end
71
71
end
72
72
73
+ def <<( other )
74
+ raise NotImplementedError , 'Mutable String methods are not supported in Opal.'
75
+ end
76
+
73
77
def ==( other )
74
78
return false unless String === other
75
79
@@ -147,6 +151,8 @@ def capitalize
147
151
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
148
152
end
149
153
154
+ alias capitalize! <<
155
+
150
156
def casecmp ( other )
151
157
other = Opal . coerce_to ( other , String , :to_str ) . to_s
152
158
@@ -201,6 +207,8 @@ def chomp(separator = $/)
201
207
self
202
208
end
203
209
210
+ alias chomp! <<
211
+
204
212
def chop
205
213
%x{
206
214
var length = self.length;
@@ -218,6 +226,8 @@ def chop
218
226
}
219
227
end
220
228
229
+ alias chop! <<
230
+
221
231
def chr
222
232
`self.charAt(0)`
223
233
end
@@ -244,6 +254,8 @@ def downcase
244
254
`self.toLowerCase()`
245
255
end
246
256
257
+ alias downcase! <<
258
+
247
259
def each_char ( &block )
248
260
return enum_for :each_char unless block_given?
249
261
@@ -318,6 +330,8 @@ def gsub(pattern, replace = undefined, &block)
318
330
}
319
331
end
320
332
333
+ alias gsub! <<
334
+
321
335
def hash
322
336
`self.toString()`
323
337
end
@@ -454,6 +468,8 @@ def lstrip
454
468
`self.replace(/^\s */, '')`
455
469
end
456
470
471
+ alias lstrip! <<
472
+
457
473
def match ( pattern , pos = undefined , &block )
458
474
if String === pattern || pattern . respond_to? ( :to_str )
459
475
pattern = /#{ Regexp . escape ( pattern . to_str ) } /
@@ -479,6 +495,8 @@ def next
479
495
}
480
496
end
481
497
498
+ alias next! <<
499
+
482
500
def ord
483
501
`self.charCodeAt(0)`
484
502
end
@@ -496,6 +514,8 @@ def reverse
496
514
`self.split('').reverse().join('')`
497
515
end
498
516
517
+ alias reverse! <<
518
+
499
519
# TODO handle case where search is regexp
500
520
def rindex ( search , offset = undefined )
501
521
%x{
@@ -596,6 +616,7 @@ def scan(pattern, &block)
596
616
alias size length
597
617
598
618
alias slice []
619
+ alias slice! <<
599
620
600
621
def split ( pattern = $; || ' ' , limit = undefined )
601
622
%x{
@@ -744,6 +765,8 @@ def squeeze(*sets)
744
765
}
745
766
end
746
767
768
+ alias squeeze! <<
769
+
747
770
def start_with? ( *prefixes )
748
771
%x{
749
772
for (var i = 0, length = prefixes.length; i < length; i++) {
@@ -762,6 +785,8 @@ def strip
762
785
`self.replace(/^\s */, '').replace(/\s *$/, '')`
763
786
end
764
787
788
+ alias strip! <<
789
+
765
790
%x{
766
791
// convert Ruby back reference to JavaScript back reference
767
792
function convertReplace(replace) {
@@ -832,7 +857,10 @@ def sub(pattern, replace = undefined, &block)
832
857
}
833
858
end
834
859
860
+ alias sub! <<
861
+
835
862
alias succ next
863
+ alias succ! <<
836
864
837
865
def sum ( n = 16 )
838
866
%x{
@@ -860,6 +888,8 @@ def swapcase
860
888
}
861
889
end
862
890
891
+ alias swapcase! <<
892
+
863
893
def to_f
864
894
%x{
865
895
if (self.charAt(0) === '_') {
@@ -1043,6 +1073,8 @@ def tr(from, to)
1043
1073
}
1044
1074
end
1045
1075
1076
+ alias tr! <<
1077
+
1046
1078
def tr_s ( from , to )
1047
1079
%x{
1048
1080
if (from.length == 0) {
@@ -1196,10 +1228,14 @@ def tr_s(from, to)
1196
1228
}
1197
1229
end
1198
1230
1231
+ alias tr_s! <<
1232
+
1199
1233
def upcase
1200
1234
`self.toUpperCase()`
1201
1235
end
1202
1236
1237
+ alias upcase! <<
1238
+
1203
1239
def freeze
1204
1240
self
1205
1241
end
0 commit comments