Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions mrbgems/mruby-symbol-ext/mrblib/symbol.rb
Expand Up @@ -62,4 +62,10 @@ def empty?
self.length == 0
end

def slice *args
to_s.slice(*args)
end

alias [] slice

end
12 changes: 12 additions & 0 deletions mrbgems/mruby-symbol-ext/test/symbol.rb
Expand Up @@ -46,3 +46,15 @@
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