Skip to content

Commit

Permalink
🔧 Add Config#with(**attrs) to make updated copies
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Jun 21, 2024
1 parent 9705844 commit b28a17b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ def update(**attrs)
self
end

# :call-seq:
# with(**attrs) -> config
# with(**attrs) {|config| } -> result
#
# Returns a shallow copy of +self+. When provided with a block, yields
# the copy to the block and returns the block's result.
#
# If any keyword arguments are given, the copy will be updated with their
# values.
#
# If +self+ is frozen, the copy will also be frozen.
def with(**attrs)
copy = dup.update(**attrs)
copy.freeze if frozen?
block_given? ? yield(copy) : copy
end

# :call-seq: to_h -> hash
#
# Returns all config attributes in a hash.
Expand Down

0 comments on commit b28a17b

Please sign in to comment.