mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Move Array#map to Ruby
Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
parent
c9a5a71695
commit
01db456196
Notes:
git
2024-11-13 20:27:44 +00:00
6 changed files with 43 additions and 12 deletions
25
array.rb
25
array.rb
|
@ -233,6 +233,31 @@ class Array
|
|||
end
|
||||
end
|
||||
|
||||
if Primitive.rb_builtin_basic_definition_p(:map)
|
||||
undef :map
|
||||
|
||||
def map # :nodoc:
|
||||
Primitive.attr! :inline_block, :c_trace
|
||||
|
||||
unless defined?(yield)
|
||||
return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, ary_enum_length)'
|
||||
end
|
||||
|
||||
_i = 0
|
||||
value = nil
|
||||
result = Primitive.ary_sized_alloc
|
||||
while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) })
|
||||
result << yield(value)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
if Primitive.rb_builtin_basic_definition_p(:collect)
|
||||
undef :collect
|
||||
alias collect map
|
||||
end
|
||||
end
|
||||
|
||||
if Primitive.rb_builtin_basic_definition_p(:select)
|
||||
undef :select
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue