Merge pull request #14389 from samford/add-options-to_s-method
Options: Add #to_s method
This commit is contained in:
commit
200cf75233
@ -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}>"
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user