summaryrefslogtreecommitdiff
path: root/include/ruby/internal/variable.h
diff options
context:
space:
mode:
authorUfuk Kayserilioglu <ufuk@paralaus.com>2022-12-22 02:27:38 +0200
committerGitHub <noreply@github.com>2022-12-21 16:27:38 -0800
commit99cee85775bc5656b942bf4e1b0568a8f40addcd (patch)
tree2411e0b27cfc55a559a50ac28eb1e0acec202e6f /include/ruby/internal/variable.h
parent398aaed2f0e56a81c5c15cc1126b6bbba79ffec0 (diff)
Add copy with changes functionality for Data objects (#6766)
Implements [Feature #19000] This commit adds copy with changes functionality for `Data` objects using a new method `Data#with`. Since Data objects are immutable, the only way to change them is by creating a copy. This PR adds a `with` method for `Data` class instances that optionally takes keyword arguments. If the `with` method is called with no arguments, the behaviour is the same as the `Kernel#dup` method, i.e. a new shallow copy is created with no field values changed. However, if keyword arguments are supplied to the `with` method, then the copy is created with the specified field values changed. For example: ```ruby Point = Data.define(:x, :y) point = Point.new(x: 1, y: 2) point.with(x: 3) # => #<data Point x: 3, y: 2> ``` Passing positional arguments to `with` or passing keyword arguments to it that do not correspond to any of the members of the Data class will raise an `ArgumentError`. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Notes
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'include/ruby/internal/variable.h')
0 files changed, 0 insertions, 0 deletions