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
e86bc6bb
Commit
e86bc6bb
authored
Jan 30, 2016
by
Akira Moroo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add String#rjust to mruby-string-ext
parent
c35a25c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
mrbgems/mruby-string-ext/mrblib/string.rb
mrbgems/mruby-string-ext/mrblib/string.rb
+23
-0
No files found.
mrbgems/mruby-string-ext/mrblib/string.rb
View file @
e86bc6bb
...
...
@@ -287,6 +287,29 @@ class String
return
newstr
.
slice
(
0
,
idx
)
end
##
# call-seq:
# str.rjust(integer, padstr=' ') -> new_str
#
# If <i>integer</i> is greater than the length of <i>str</i>, returns a new
# <code>String</code> of length <i>integer</i> with <i>str</i> right justified
# and padded with <i>padstr</i>; otherwise, returns <i>str</i>.
#
# "hello".rjust(4) #=> "hello"
# "hello".rjust(20) #=> " hello"
# "hello".rjust(20, '1234') #=> "123412341234123hello"
def
rjust
(
idx
,
padstr
=
' '
)
if
idx
<=
self
.
size
return
self
end
padsize
=
idx
-
self
.
size
newstr
=
padstr
.
dup
while
newstr
.
size
<=
padsize
newstr
<<
padstr
end
return
newstr
.
slice
(
0
,
padsize
)
+
self
end
# str.upto(other_str, exclusive=false) {|s| block } -> str
# str.upto(other_str, exclusive=false) -> an_enumerator
#
...
...
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