Implement Symbol#slice and Symbol#[] in mruby-symbol-ext.

This commit is contained in:
take_cheeze
2014-07-18 22:30:07 +09:00
parent 23b6e22cf0
commit 2249cf7c7f
2 changed files with 16 additions and 0 deletions
@@ -62,4 +62,10 @@ class Symbol
self.length == 0
end
def slice *args
to_s.slice(*args).to_sym
end
alias [] slice
end
+10
View File
@@ -46,3 +46,13 @@ end
assert('Symbol#intern') do
assert_equal :test, :test.intern
end
assert('Symbol#slice') do
assert_equal :a, :abc.slice(0)
assert_equal :ab, :abc.slice(0, 2)
end
assert('Symbol#[]') do
assert_equal :a, :abc[0]
assert_equal :ab, :abc[0, 2]
end