summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-symbol-ext
diff options
context:
space:
mode:
authorskandhas <[email protected]>2013-10-08 21:47:11 +0800
committerskandhas <[email protected]>2013-10-08 21:47:11 +0800
commit81c0fda8ecdd6dd4eab8ed64c968d841617df333 (patch)
treebaf4d185be7678a0b07928791242bf366e49518d /mrbgems/mruby-symbol-ext
parent9295f6ae4916854c92cd3430cd0ee5d3b2f1b2df (diff)
downloadmruby-81c0fda8ecdd6dd4eab8ed64c968d841617df333.tar.gz
mruby-81c0fda8ecdd6dd4eab8ed64c968d841617df333.zip
add some methods to Symbol
Diffstat (limited to 'mrbgems/mruby-symbol-ext')
-rw-r--r--mrbgems/mruby-symbol-ext/mrblib/symbol.rb51
-rw-r--r--mrbgems/mruby-symbol-ext/test/symbol.rb22
2 files changed, 73 insertions, 0 deletions
diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
index f716162e8..a4e8ef7a8 100644
--- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
@@ -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
diff --git a/mrbgems/mruby-symbol-ext/test/symbol.rb b/mrbgems/mruby-symbol-ext/test/symbol.rb
index 741315d74..35bb31aef 100644
--- a/mrbgems/mruby-symbol-ext/test/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/test/symbol.rb
@@ -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