summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authorgo.kikuta <[email protected]>2015-08-20 17:52:30 +0900
committergo.kikuta <[email protected]>2015-08-21 14:54:01 +0900
commit11524f6f678fde684941937413b6bc2cba23b630 (patch)
treef9ca50806522a70fcb920fc85ac3b296f3d8e909 /mrblib
parentcb870de2b52fad05c8ba0b23893008d0ba77ac3b (diff)
downloadmruby-11524f6f678fde684941937413b6bc2cba23b630.tar.gz
mruby-11524f6f678fde684941937413b6bc2cba23b630.zip
string.rb: refactor code (remove redundant code)
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/string.rb26
1 files changed, 7 insertions, 19 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 23cf02e97..05b13cb43 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -80,12 +80,8 @@ class String
# ISO 15.2.10.5.19
def gsub!(*args, &block)
str = self.gsub(*args, &block)
- if str != self
- self.replace(str)
- self
- else
- nil
- end
+ return nil if str == self
+ self.replace(str)
end
##
@@ -129,12 +125,8 @@ class String
# ISO 15.2.10.5.37
def sub!(*args, &block)
str = self.sub(*args, &block)
- if str != self
- self.replace(str)
- self
- else
- nil
- end
+ return nil if str == self
+ self.replace(str)
end
##
@@ -165,20 +157,16 @@ class String
# Modify +self+ by replacing the content of +self+
# at the position +pos+ with +value+.
def []=(pos, value)
- if pos < 0
- pos += self.length
- end
+ pos += self.length if pos < 0
b = self[0, pos]
- a = self[pos+1..-1]
+ a = self[pos + 1..-1]
self.replace([b, value, a].join(''))
end
##
# ISO 15.2.10.5.3
def =~(re)
- if re.respond_to? :to_str
- raise TypeError, "type mismatch: String given"
- end
+ raise TypeError, "type mismatch: String given" if re.respond_to? :to_str
re =~ self
end