Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implements [Feature #21455] Add a block argument to Array#join #13731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leoarnold
Copy link
Contributor

@leoarnold leoarnold commented Jun 27, 2025

I sometimes come across code like this where
the Array#join at the end can easily
be overlooked or stands out like a sore thumb:

hex_string = string.bytes.map do |byte|
  format('%02X', byte)
end.join(' ')

It seems idiomatic and more succinct
to pass the block to Array#join directly:

hex_string = string.bytes.join(' ') do |byte|
  format('%02X', byte)
end

@jeremyevans
Copy link
Contributor

If you would like this to be considered, please submit a feature request on https://bugs.ruby-lang.org/, explaining what you see as the costs and benefits of the feature, and linking to this pull request.

@leoarnold
Copy link
Contributor Author

@leoarnold leoarnold changed the title Add a block argument to Array#join Implements [Feature #21455] Add a block argument to Array#join Jun 28, 2025
@leoarnold leoarnold force-pushed the leoarnold/array/block branch from 46f2418 to ca0a3d9 Compare June 28, 2025 00:40
I sometimes come across code like this where
the `Array#join` at the end can easily
be overlooked or stands out like a sore thumb:

```ruby
hex_string = string.bytes.map do |byte|
  format('%02X', byte)
end.join(' ')
```

It seems idiomatic and more succinct
to pass the block to `Array#join` directly:

```ruby
hex_string = string.bytes.join(' ') do |byte|
  format('%02X', byte)
end
```
@leoarnold leoarnold force-pushed the leoarnold/array/block branch from ca0a3d9 to f69464a Compare June 28, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants