Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 86bf3170ea8f
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 648a80cbd52c
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 9, 2016

  1. Copy the full SHA
    176b198 View commit details
  2. Merge pull request #3558 from andre-richter/fix_puts

    puts: Check if argument responds to :to_ary, instead of checking its type being Array
    brixen committed Jan 9, 2016
    Copy the full SHA
    648a80c View commit details
Showing with 12 additions and 3 deletions.
  1. +2 −2 kernel/common/io.rb
  2. +10 −1 spec/ruby/core/io/puts_spec.rb
4 changes: 2 additions & 2 deletions kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -1794,9 +1794,9 @@ def puts(*args)
str = ""
elsif Thread.guarding? arg
str = "[...]"
elsif arg.kind_of?(Array)
elsif arg.respond_to?(:to_ary)
Thread.recursion_guard arg do
arg.each do |a|
arg.to_ary.each do |a|
puts a
end
end
11 changes: 10 additions & 1 deletion spec/ruby/core/io/puts_spec.rb
Original file line number Diff line number Diff line change
@@ -37,7 +37,16 @@
@io.puts(nil, nil).should == nil
end

it "calls to_s before writing non-string objects" do
it "calls to_ary before writing non-string objects that respond to :to_ary" do
object = mock('hola')
object.should_receive(:to_ary).and_return(["hola"])

@io.should_receive(:write).with("hola")
@io.should_receive(:write).with("\n")
@io.puts(object).should == nil
end

it "calls to_s before writing non-string objects that don't respond to :to_ary" do
object = mock('hola')
object.should_receive(:to_s).and_return("hola")