⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (805 Bytes)
Bug #14015
ยป yield_arity.rb
marcandre (Marc-Andre Lafortune)
, 10/14/2017 08:25 PM
TEST
=
%i[each find sort_by grep grep_v count detect find_index find_all select reject
map flat_map partition group_by all? any? one? none?
min_by max_by minmax_by reverse_each take_while drop_while sum uniq]
match_all
=
Object
.
new
;
def
match_all
.
===
(
x
);
true
;
end
ARGS
=
{
grep:
match_all
,
grep_v:
/never_match/
}
class
<<
o
=
Object
.
new
include
Enumerable
def
each
return
to_enum
unless
block_given?
yield
:a
,
1
end
def
foo
(
a
,
b
)
end
end
m
=
o
.
method
(
:foo
)
ok
=
[{
a:
1
},
o
,
{
a:
1
}.
each
,
o
.
each
].
map
do
|
receiver
|
TEST
.
select
do
|
method
|
(
receiver
.
send
(
method
,
*
ARGS
[
method
],
&
m
);
:ok
)
rescue
false
end
end
labels
=
[
'Hash'
,
'Custom yield'
,
'Hash#each'
,
'Custom yield#each'
]
puts
"Takes arity 2 blocks in Ruby
#{
RUBY_VERSION
}
"
,
*
labels
.
zip
(
ok
.
map
{
|
l
|
l
.
join
(
', '
)}).
flatten
(1-1/1)
Loading...