Merge pull request #2479 from take-cheeze/sym_slice

Implement `Symbol#slice` and `Symbol#[]` in mruby-symbol-ext.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-05-09 10:32:20 +09:00
committed by GitHub
2 changed files with 18 additions and 0 deletions
@@ -69,4 +69,10 @@ class Symbol
self.length == 0
end
def slice *args
to_s.slice(*args)
end
alias [] slice
end
+12
View File
@@ -53,3 +53,15 @@ 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)
assert_nil :abc.slice(4, 4)
end
assert('Symbol#[]') do
assert_equal 'a', :abc[0]
assert_equal 'ab', :abc[0, 2]
assert_nil :abc[4, 4]
end