Unverified Commit 3f7137fe authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4258 from shuujii/extend-only-when-necessary

Extend only when necessary in `lib/mruby-core-ext.rb`
parents 32067b50 668ed605
...@@ -18,18 +18,20 @@ class String ...@@ -18,18 +18,20 @@ class String
end end
# Compatible with 1.9 on 1.8 # Compatible with 1.9 on 1.8
def %(params) unless (sprintf("%{a}", :a => 1) rescue false)
if params.is_a?(Hash) def %(params)
str = self.clone if params.is_a?(Hash)
params.each do |k, v| str = self.clone
str.gsub!("%{#{k}}") { v } params.each do |k, v|
end str.gsub!("%{#{k}}") { v }
str end
else str
if params.is_a?(Array)
sprintf(self, *params)
else else
sprintf(self, params) if params.is_a?(Array)
sprintf(self, *params)
else
sprintf(self, params)
end
end end
end end
end end
...@@ -37,17 +39,21 @@ end ...@@ -37,17 +39,21 @@ end
class Symbol class Symbol
# Compatible with 1.9 on 1.8 # Compatible with 1.9 on 1.8
def to_proc unless method_defined?(:to_proc)
proc { |obj, *args| obj.send(self, *args) } def to_proc
proc { |obj, *args| obj.send(self, *args) }
end
end end
end end
module Enumerable module Enumerable
# Compatible with 1.9 on 1.8 # Compatible with 1.9 on 1.8
def each_with_object(memo) unless method_defined?(:each_with_object)
return to_enum :each_with_object, memo unless block_given? def each_with_object(memo)
each { |obj| yield obj, memo } return to_enum :each_with_object, memo unless block_given?
memo each { |obj| yield obj, memo }
memo
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment