Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
3f7137fe
Unverified
Commit
3f7137fe
authored
Feb 02, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Feb 02, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4258 from shuujii/extend-only-when-necessary
Extend only when necessary in `lib/mruby-core-ext.rb`
parents
32067b50
668ed605
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
lib/mruby-core-ext.rb
lib/mruby-core-ext.rb
+23
-17
No files found.
lib/mruby-core-ext.rb
View file @
3f7137fe
...
...
@@ -18,18 +18,20 @@ class String
end
# Compatible with 1.9 on 1.8
def
%
(
params
)
if
params
.
is_a?
(
Hash
)
str
=
self
.
clone
params
.
each
do
|
k
,
v
|
str
.
gsub!
(
"%{
#{
k
}
}"
)
{
v
}
end
str
else
if
params
.
is_a?
(
Array
)
sprintf
(
self
,
*
params
)
unless
(
sprintf
(
"%{a}"
,
:a
=>
1
)
rescue
false
)
def
%
(
params
)
if
params
.
is_a?
(
Hash
)
str
=
self
.
clone
params
.
each
do
|
k
,
v
|
str
.
gsub!
(
"%{
#{
k
}
}"
)
{
v
}
end
str
else
sprintf
(
self
,
params
)
if
params
.
is_a?
(
Array
)
sprintf
(
self
,
*
params
)
else
sprintf
(
self
,
params
)
end
end
end
end
...
...
@@ -37,17 +39,21 @@ end
class
Symbol
# Compatible with 1.9 on 1.8
def
to_proc
proc
{
|
obj
,
*
args
|
obj
.
send
(
self
,
*
args
)
}
unless
method_defined?
(
:to_proc
)
def
to_proc
proc
{
|
obj
,
*
args
|
obj
.
send
(
self
,
*
args
)
}
end
end
end
module
Enumerable
# Compatible with 1.9 on 1.8
def
each_with_object
(
memo
)
return
to_enum
:each_with_object
,
memo
unless
block_given?
each
{
|
obj
|
yield
obj
,
memo
}
memo
unless
method_defined?
(
:each_with_object
)
def
each_with_object
(
memo
)
return
to_enum
:each_with_object
,
memo
unless
block_given?
each
{
|
obj
|
yield
obj
,
memo
}
memo
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment