Skip to content

Commit b8dbeea

Browse files
aardvark179chrisseaton
authored andcommitted
Fix failing array specs
1 parent 9014897 commit b8dbeea

File tree

10 files changed

+30
-54
lines changed

10 files changed

+30
-54
lines changed

spec/tags/core/array/append_tags.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

spec/tags/core/array/difference_tags.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

spec/tags/core/array/filter_tags.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

spec/tags/core/array/flatten_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/tags/core/array/prepend_tags.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

spec/tags/core/array/union_tags.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/truffle/methods/Array.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[]
99
[]=
1010
any?
11+
append
1112
assoc
1213
at
1314
bsearch
@@ -24,6 +25,7 @@ cycle
2425
delete
2526
delete_at
2627
delete_if
28+
difference
2729
dig
2830
drop
2931
drop_while
@@ -33,6 +35,8 @@ empty?
3335
eql?
3436
fetch
3537
fill
38+
filter
39+
filter!
3640
find_index
3741
first
3842
flatten
@@ -54,6 +58,7 @@ min
5458
pack
5559
permutation
5660
pop
61+
prepend
5762
product
5863
push
5964
rassoc
@@ -88,6 +93,7 @@ to_ary
8893
to_h
8994
to_s
9095
transpose
96+
union
9197
uniq
9298
uniq!
9399
unshift

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ public DynamicObject append(DynamicObject array, Object value) {
16541654

16551655
}
16561656

1657-
@CoreMethod(names = "push", rest = true, optional = 1, raiseIfFrozenSelf = true)
1657+
@CoreMethod(names = { "push", "append" }, rest = true, optional = 1, raiseIfFrozenSelf = true)
16581658
public abstract static class PushNode extends ArrayCoreMethodNode {
16591659

16601660
@Child private ArrayAppendOneNode appendOneNode = ArrayAppendOneNode.create();

src/main/ruby/core/array.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ def delete_if(&block)
354354
self
355355
end
356356

357+
def difference(*others)
358+
other = []
359+
others.each { |a| other = other | a }
360+
self - other
361+
end
362+
357363
def dig(idx, *more)
358364
result = self.at(idx)
359365
if result.nil? || more.empty?
@@ -495,6 +501,8 @@ def fetch(idx, default=undefined)
495501
self
496502
end
497503

504+
alias_method :filter, :select
505+
498506
def first(n = undefined)
499507
return at(0) if undefined.equal?(n)
500508

@@ -1120,6 +1128,8 @@ def select!(&block)
11201128
Truffle.invoke_primitive(:steal_array_storage, self, ary) unless size == ary.size
11211129
end
11221130

1131+
alias_method :filter!, :select!
1132+
11231133
def shuffle(options = undefined)
11241134
return dup.shuffle!(options) if instance_of? Array
11251135
Array.new(self).shuffle!(options)
@@ -1173,8 +1183,8 @@ def to_ary
11731183
self
11741184
end
11751185

1176-
def to_h
1177-
super
1186+
def to_h &block
1187+
super(*self, &block)
11781188
end
11791189

11801190
def transpose
@@ -1199,6 +1209,12 @@ def transpose
11991209
out
12001210
end
12011211

1212+
def union(*others)
1213+
res = Array.new(self).uniq
1214+
others.each { |other| res = res | other }
1215+
res
1216+
end
1217+
12021218
def unshift(*values)
12031219
Truffle.check_frozen
12041220

@@ -1207,6 +1223,8 @@ def unshift(*values)
12071223
self
12081224
end
12091225

1226+
alias_method :prepend, :unshift
1227+
12101228
def values_at(*args)
12111229
out = []
12121230

src/main/ruby/core/type.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def self.check_funcall_default(recv, meth, args, default)
324324
respond = check_funcall_respond_to(recv, meth, true)
325325
return default if respond == 0
326326
unless check_funcall_callable(recv, meth)
327-
return check_funcall_missing(recv, meth, args, respond, default);
327+
return check_funcall_missing(recv, meth, args, respond, default, true);
328328
end
329329
recv.__send__(meth)
330330
end
@@ -339,8 +339,8 @@ def self.check_funcall_respond_to(obj, meth, priv)
339339
end
340340
end
341341

342-
def self.check_funcall_missing(recv, meth, args, respond, default)
343-
ret = basic_obj_respond_to_missing(recv, meth, false) #PRIV false
342+
def self.check_funcall_missing(recv, meth, args, respond, default, priv = false)
343+
ret = basic_obj_respond_to_missing(recv, meth, priv)
344344
respond_to_missing = !undefined.equal?(ret)
345345
return default if respond_to_missing and !ret
346346
ret = default

0 commit comments

Comments
 (0)