Move `Symbol#to_proc` to the core from `mruby-symbol-ext` gem.

Even though `Symbol#to_proc` is not included in ISO standard, the
`some_method(&:method_name)` is used very widely and convenient.
So we moved it to the core.
parent 19d3bb2d
...@@ -3,12 +3,6 @@ class Symbol ...@@ -3,12 +3,6 @@ class Symbol
alias intern to_sym alias intern to_sym
def to_proc
->(obj,*args,&block) do
obj.__send__(self, *args, &block)
end
end
## ##
# call-seq: # call-seq:
# sym.capitalize -> symbol # sym.capitalize -> symbol
......
## ##
# Symbol(Ext) Test # Symbol(Ext) Test
assert('Symbol#to_proc') do
assert_equal 5, :abs.to_proc[-5]
end
assert('Symbol.all_symbols') do assert('Symbol.all_symbols') do
foo = [:__symbol_test_1, :__symbol_test_2, :__symbol_test_3].sort foo = [:__symbol_test_1, :__symbol_test_2, :__symbol_test_3].sort
symbols = Symbol.all_symbols.select{|sym|sym.to_s.include? '__symbol_test'}.sort symbols = Symbol.all_symbols.select{|sym|sym.to_s.include? '__symbol_test'}.sort
......
class Symbol
def to_proc
->(obj,*args,&block) do
obj.__send__(self, *args, &block)
end
end
end
...@@ -28,3 +28,7 @@ end ...@@ -28,3 +28,7 @@ end
assert('Symbol#to_sym', '15.2.11.3.4') do assert('Symbol#to_sym', '15.2.11.3.4') do
assert_equal :abc, :abc.to_sym assert_equal :abc, :abc.to_sym
end end
assert('Symbol#to_proc') do
assert_equal 5, :abs.to_proc[-5]
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment