Skip to content

Commit b1d0650

Browse files
committedOct 31, 2014
Raise NotImplementedError in String mutable meths
This is for improved usability, previously method_missing was called.
1 parent 9cd638c commit b1d0650

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎opal/corelib/string.rb

+36
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def <=>(other)
7070
end
7171
end
7272

73+
def <<(other)
74+
raise NotImplementedError, 'Mutable String methods are not supported in Opal.'
75+
end
76+
7377
def ==(other)
7478
return false unless String === other
7579

@@ -147,6 +151,8 @@ def capitalize
147151
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
148152
end
149153

154+
alias capitalize! <<
155+
150156
def casecmp(other)
151157
other = Opal.coerce_to(other, String, :to_str).to_s
152158

@@ -201,6 +207,8 @@ def chomp(separator = $/)
201207
self
202208
end
203209

210+
alias chomp! <<
211+
204212
def chop
205213
%x{
206214
var length = self.length;
@@ -218,6 +226,8 @@ def chop
218226
}
219227
end
220228

229+
alias chop! <<
230+
221231
def chr
222232
`self.charAt(0)`
223233
end
@@ -244,6 +254,8 @@ def downcase
244254
`self.toLowerCase()`
245255
end
246256

257+
alias downcase! <<
258+
247259
def each_char(&block)
248260
return enum_for :each_char unless block_given?
249261

@@ -318,6 +330,8 @@ def gsub(pattern, replace = undefined, &block)
318330
}
319331
end
320332

333+
alias gsub! <<
334+
321335
def hash
322336
`self.toString()`
323337
end
@@ -454,6 +468,8 @@ def lstrip
454468
`self.replace(/^\s*/, '')`
455469
end
456470

471+
alias lstrip! <<
472+
457473
def match(pattern, pos = undefined, &block)
458474
if String === pattern || pattern.respond_to?(:to_str)
459475
pattern = /#{Regexp.escape(pattern.to_str)}/
@@ -479,6 +495,8 @@ def next
479495
}
480496
end
481497

498+
alias next! <<
499+
482500
def ord
483501
`self.charCodeAt(0)`
484502
end
@@ -496,6 +514,8 @@ def reverse
496514
`self.split('').reverse().join('')`
497515
end
498516

517+
alias reverse! <<
518+
499519
# TODO handle case where search is regexp
500520
def rindex(search, offset = undefined)
501521
%x{
@@ -596,6 +616,7 @@ def scan(pattern, &block)
596616
alias size length
597617

598618
alias slice []
619+
alias slice! <<
599620

600621
def split(pattern = $; || ' ', limit = undefined)
601622
%x{
@@ -744,6 +765,8 @@ def squeeze(*sets)
744765
}
745766
end
746767

768+
alias squeeze! <<
769+
747770
def start_with?(*prefixes)
748771
%x{
749772
for (var i = 0, length = prefixes.length; i < length; i++) {
@@ -762,6 +785,8 @@ def strip
762785
`self.replace(/^\s*/, '').replace(/\s*$/, '')`
763786
end
764787

788+
alias strip! <<
789+
765790
%x{
766791
// convert Ruby back reference to JavaScript back reference
767792
function convertReplace(replace) {
@@ -832,7 +857,10 @@ def sub(pattern, replace = undefined, &block)
832857
}
833858
end
834859

860+
alias sub! <<
861+
835862
alias succ next
863+
alias succ! <<
836864

837865
def sum(n = 16)
838866
%x{
@@ -860,6 +888,8 @@ def swapcase
860888
}
861889
end
862890

891+
alias swapcase! <<
892+
863893
def to_f
864894
%x{
865895
if (self.charAt(0) === '_') {
@@ -1043,6 +1073,8 @@ def tr(from, to)
10431073
}
10441074
end
10451075

1076+
alias tr! <<
1077+
10461078
def tr_s(from, to)
10471079
%x{
10481080
if (from.length == 0) {
@@ -1196,10 +1228,14 @@ def tr_s(from, to)
11961228
}
11971229
end
11981230

1231+
alias tr_s! <<
1232+
11991233
def upcase
12001234
`self.toUpperCase()`
12011235
end
12021236

1237+
alias upcase! <<
1238+
12031239
def freeze
12041240
self
12051241
end

0 commit comments

Comments
 (0)
Please sign in to comment.