Merge pull request #14389 from samford/add-options-to_s-method

Options: Add #to_s method
This commit is contained in:
Mike McQuaid 2023-01-20 15:21:18 +00:00 committed by GitHub
commit 200cf75233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -145,6 +145,11 @@ class Options
alias to_ary to_a
sig { returns(String) }
def to_s
@options.map(&:to_s).join(" ")
end
sig { returns(String) }
def inspect
"#<#{self.class.name}: #{to_a.inspect}>"

View File

@ -90,6 +90,14 @@ describe Options do
expect(described_class.create(array).sort).to eq([option1, option2].sort)
end
specify "#to_s" do
expect(options.to_s).to eq("")
options << Option.new("first")
expect(options.to_s).to eq("--first")
options << Option.new("second")
expect(options.to_s).to eq("--first --second")
end
specify "#inspect" do
expect(options.inspect).to eq("#<Options: []>")
options << Option.new("foo")