Commit 81c0fda8 authored by skandhas's avatar skandhas

add some methods to Symbol

parent 9295f6ae
......@@ -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
......@@ -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
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