Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public IRubyObject initialize(final ThreadContext context, IRubyObject enume, fi
} else if (enume instanceof RubySet set) {
allocHash(context, set.size());
for ( IRubyObject elem : set.elementsOrdered() ) {
invokeAdd(context, block.yield(context, elem));
if (block.isGiven()) elem = block.yield(context, elem);
invokeAdd(context, elem);
}
return set; // done
} else {
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby/core/set/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
s.size.should eql(0)
end

it "should initialize with set" do
o = Set.new([1, 2])
s = Set.new(o)
s.size.should eql(2)
s.should include(1)
s.should include(2)
end

it "should initialize with set and block" do
o = Set.new([1, 2])
s = Set.new(o) { |e| e + 2 }
s.size.should eql(2)
s.should include(3)
s.should include(4)
end

it "should initialize with just block" do
s = Set.new { |x| x * x }
s.size.should eql(0)
Expand Down
Loading