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
480e3297
Commit
480e3297
authored
Oct 09, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1534 from skandhas/pr-add-some-symbol-methods
Add some methods to Symbol
parents
7b0baded
81c0fda8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
mrbgems/mruby-symbol-ext/mrblib/symbol.rb
mrbgems/mruby-symbol-ext/mrblib/symbol.rb
+51
-0
mrbgems/mruby-symbol-ext/test/symbol.rb
mrbgems/mruby-symbol-ext/test/symbol.rb
+22
-0
No files found.
mrbgems/mruby-symbol-ext/mrblib/symbol.rb
View file @
480e3297
...
...
@@ -6,4 +6,55 @@ class Symbol
end
end
##
# call-seq:
# sym.length -> integer
#
# Same as <code>sym.to_s.length</code>.
def
length
self
.
to_s
.
length
end
alias
:size
:length
##
# call-seq:
# sym.capitalize -> symbol
#
# Same as <code>sym.to_s.capitalize.intern</code>.
def
capitalize
self
.
to_s
.
capitalize
.
intern
end
##
# call-seq:
# sym.downcase -> symbol
#
# Same as <code>sym.to_s.downcase.intern</code>.
def
downcase
self
.
to_s
.
downcase
.
intern
end
##
# call-seq:
# sym.upcase -> symbol
#
# Same as <code>sym.to_s.upcase.intern</code>.
def
upcase
self
.
to_s
.
upcase
.
intern
end
#
# call-seq:
# sym.empty? -> true or false
#
# Returns that _sym_ is :"" or not.
def
empty?
self
.
to_s
.
empty?
end
end
mrbgems/mruby-symbol-ext/test/symbol.rb
View file @
480e3297
...
...
@@ -10,3 +10,25 @@ assert('Symbol.all_symbols') do
symbols
=
Symbol
.
all_symbols
.
select
{
|
sym
|
sym
.
to_s
.
include?
'__symbol_test'
}.
sort
assert_equal
foo
,
symbols
end
assert
(
"Symbol#length"
)
do
assert_equal
5
,
:hello
.
size
assert_equal
5
,
:mruby
.
length
end
assert
(
"Symbol#capitalize"
)
do
assert_equal
:Hello
,
:hello
.
capitalize
assert_equal
:Hello
,
:HELLO
.
capitalize
end
assert
(
"Symbol#downcase"
)
do
assert_equal
:hello
,
:hEllO
.
downcase
end
assert
(
"Symbol#upcase"
)
do
assert_equal
:HELLO
,
:hEllO
.
upcase
end
assert
(
"Symbol#empty?"
)
do
assert_true
:''
.
empty?
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