ruby / ruby/pathname

Add puts

Open
#39 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
32
Forks
24
Avg merge
13h 2m
Merged PRs (30d)
1

Description

Why

Hello. 👋

I keep running into situations where I'd like to use puts when swapping out an IO-like object (i.e. IO, StringIO, File, Kernel, Pathname, and so forth) and can't find any mention as to why Pathname#puts isn't supported as found in similar IO-like objects.

Allowing the use of Pathname#puts would make injecting IO-like dependencies behave similarly in terms of writing with a newline. This would allow anyone to more easily swap these objects out while still quacking like a duck so-to-speak. I bring this up because Pathname#write is supported but am confused as to why Pathname#puts is not.

How

Would it be possible to add Pathname#puts or is there some other reason why this isn't exposed? The workaround is to use Pathname#write by manually adding a new line each time. Example:

path = Pathname "test.txt"
path.write "Hi\n"

This achieves the same functionality but is tedious especially if you are not using a string literal each time. Example:

path = Pathname "test.txt"

# Tedious
path.write "#{some_computed_result}\n"

# Nicer (proposed solution) because you don't have to do the extra work of string concatenation.
path.puts some_computed_result

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Pathname#write and comparing its behavior with puts on the IO-like objects named in the issue. Done means Pathname exposes puts so callers can write values with a newline without manually appending one.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.