mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Implement Symbol#slice and Symbol#[] in mruby-symbol-ext.
This commit is contained in:
@@ -62,4 +62,10 @@ class Symbol
|
||||
self.length == 0
|
||||
end
|
||||
|
||||
def slice *args
|
||||
to_s.slice(*args).to_sym
|
||||
end
|
||||
|
||||
alias [] slice
|
||||
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user