zverok
b3d57fdd64
Docs: Update Struct docs about keyword initialization
2022-12-23 18:09:49 +02:00
Ufuk Kayserilioglu
99cee85775
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>
2022-12-21 16:27:38 -08:00
Nobuyoshi Nakada
5872fd6f6c
[Feature #19163 ] Marshal-loaded Data object also should be frozen
2022-12-02 00:56:52 +09:00
Nobuyoshi Nakada
a14a1a5626
[Feature #19163 ] Data object should be frozen
2022-12-02 00:56:52 +09:00
Alan Wu
5752d11f1f
Use RTEST and add test for GH-6832
...
Technically we shouldn't see Qfalse now, but RTEST also compiles down to
just one branch anyways. Pretty contrived issue, but easy to fix.
2022-11-30 16:27:39 -05:00
Zack Deveau
4b9d10b833
struct.c (struct_ivar_get): add conditional for potential Qnil returned by rb_class_superclass
...
struct_ivar_get recently started using rb_class_superclass to
resolve super instead of RCLASS_SUPER. This change made
Qnil a possible case we need to return from within the
struct_ivar_get for loop.
2022-11-30 16:27:39 -05:00
S-H-GAMELINKS
1f4f6c9832
Using UNDEF_P macro
2022-11-16 18:58:33 +09:00
Yuri Smirnov
13e87e5049
fix Data docs ( #6497 )
2022-10-06 10:13:17 -07:00
Nobuyoshi Nakada
cbd82f5250
Cannot `define` from defined `Data` class again
2022-10-03 23:28:01 +09:00
Nobuyoshi Nakada
56f2fd3bc9
Use the dedicated function to check arity
2022-10-01 16:24:36 +09:00
Nobuyoshi Nakada
15d3b7fe6d
Fix an out of bound access
2022-10-01 16:20:22 +09:00
Nobuyoshi Nakada
c767618d4c
Do not define the method only for RDoc
...
`Data.members` fails an assertion.
2022-10-01 15:36:01 +09:00
Victor Shepelev
ad651925e3
Add Data class implementation: Simple immutable value object
2022-09-30 18:23:19 +09:00
Nobuyoshi Nakada
cfe10e482e
[DOC] Update `Struct#new` behavior with `keyword_init: true`
2022-09-09 18:58:07 +09:00
Peter Zhu
efb91ff19b
Rename rb_ary_tmp_new to rb_ary_hidden_new
...
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
2022-07-26 09:12:09 -04:00
Takashi Kokubun
5b21e94beb
Expand tabs [ci skip]
...
[Misc #18891 ]
2022-07-21 09:42:04 -07:00
John Hawthorn
adc709adb8
Don't attempt to read ivars on T_ICLASS in struct ( #5664 )
2022-05-26 11:54:15 -07:00
Peter Zhu
54b53e2c8f
[ci skip] Fix docs
2022-04-13 10:43:23 -04:00
Burdette Lamar
ffcdbedbfb
Repaired What's Here sections for Range, String, Symbol, Struct ( #5735 )
...
Repaired What's Here sections for Range, String, Symbol, Struct.
2022-03-30 13:46:24 -05:00
Nobuyoshi Nakada
e660b934b9
A positional Hash is not keyword arguments [Bug #18632 ]
2022-03-17 20:53:41 +09:00
Nobuyoshi Nakada
50c972a1ae
[DOC] Simplify operator method references
2022-02-12 12:38:36 +09:00
Peter Zhu
a32e5e1b97
[DOC] Use RDoc link style for links in the same class/module
...
I used this regex:
(?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+)
And performed a global find & replace for this:
rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Peter Zhu
f9a2802bc5
[DOC] Use RDoc link style for links to other classes/modules
...
I used this regex:
([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+)
And performed a global find & replace for this:
rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Burdette Lamar
a07fa198a6
Improve links to labels in string.c and struct.c ( #5531 )
2022-02-06 09:44:40 -06:00
Nobuyoshi Nakada
c956f979e5
Initialize Struct by calling with keyword arguments
2021-12-26 23:28:54 +09:00
Kazuhiro NISHIYAMA
04f07713d1
Fix typos [ci skip]
2021-12-25 10:33:49 +09:00
zverok
fed1629ada
Fix StructClass:: class method docs
2021-12-24 10:29:31 +09:00
Nobuyoshi Nakada
c5ec05d047
`struct_pos_num` is no longer used
2021-11-20 21:32:57 +09:00
Koichi Sasada
82ea287018
optimize `Struct` getter/setter
...
Introduce new optimized method type
`OPTIMIZED_METHOD_TYPE_STRUCT_AREF/ASET` with index information.
2021-11-19 08:32:39 +09:00
Nobuyoshi Nakada
4fb71575e2
[DOC] Fix code markup [ci skip]
...
Code markup in RDoc must not be concatenated with anothr word.
2021-10-25 01:04:51 +09:00
S.H
dc9112cf10
Using NIL_P macro instead of `== Qnil`
2021-10-03 22:34:45 +09:00
Burdette Lamar
2cf1014362
Enhanced RDoc for Struct ( #4895 )
...
Revises introductory material.
Adds section "What's Here".
Adds previously missing documentation for method #deconstruct_keys.
2021-09-27 18:17:47 -05:00
Burdette Lamar
39a6bf5513
Enhanced RDoc for Struct ( #4891 )
...
Treats:
#values_at
#select
#==
#hash
#eql?
#size
#dig
2021-09-24 18:41:02 -05:00
Burdette Lamar
bbdfce96a2
Enhanced RDoc for Struct ( #4890 )
...
Treated:
#each
#each_pair
#inspect
#to_a
#to_h
#[]
#[]=
2021-09-24 10:35:19 -05:00
Burdette Lamar
b38d2bf118
Enhance RDoc for Struct ( #4885 )
...
Treats #members and ::new.
2021-09-23 17:21:40 -05:00
Nobuyoshi Nakada
a27c274f04
[DOC] Fix broken links [ci skip]
...
* As the "doc/" prefix is specified by the `--page-dir` option,
remove from the rdoc references.
* Refer to the original .rdoc instead of the converted .html.
2021-09-15 14:16:14 +09:00
S-H-GAMELINKS
56065f0686
Using SYMBOL_P macro
2021-09-11 08:48:56 +09:00
Nobuyoshi Nakada
3e7a7fb28a
Make Struct#keyword_init? return nil by default [Feature #18008 ]
2021-07-15 22:24:02 +09:00
Nobuyoshi Nakada
33bea3bdff
Regularize keyword_init values not to hold the argument object
2021-07-15 21:32:04 +09:00
hkdnet
1a63754416
struct.c: Add keyword_init? singleton method for StructClass ( #4609 )
...
Fixes [Feature #18008 ]
2021-07-15 18:14:27 +09:00
Takashi Kokubun
8d099aa040
Warn Struct#initialize with only keyword args ( #4070 )
...
* Warn Struct#initialize with only keyword args
A part of [Feature #16806 ]
* Do not warn if `keyword_init: false`
is explicitly specified
* Add a NEWS entry
* s/in/from/
* Make sure all fields are initialized
2021-01-17 01:35:54 -08:00
卜部昌平
99093e1600
RHASH_TBL: is now ext-only
...
It seems almost no internal codes use RHASH_TBL any longer. Why not
just eliminate it entirely, so that the macro can be purely ext-only.
2020-08-19 15:10:53 +09:00
Burdette Lamar
c84ccf1a07
Fix links to Dig Methods document ( #3421 )
...
* Fix links to Dig Methods document
* Fix links to Dig Methods document
2020-08-14 18:55:04 -05:00
Burdette Lamar
22fd617aa5
Adding doc/dig_methods.rdoc and links to it ( #3416 )
...
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct.
CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon.
The art to the thing is to figure out how much (or how little) to say at each #dig.
2020-08-13 13:16:27 -05:00
卜部昌平
f66e0212ef
precalc invokebuiltin destinations
...
Noticed that struct rb_builtin_function is a purely compile-time
constant. MJIT can eliminate some runtime calculations by statically
generate dedicated C code generator for each builtin functions.
2020-07-13 08:56:18 +09:00
Takashi Kokubun
167d139487
Inline builtin struct aref
...
We don't do this for aset because it might raise a FrozenError.
```
$ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' benchmark/mjit_struct_aref.yml --repeat-count=4
before: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6
) [x86_64-linux]
after: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) [x86_64-linux]
last_commit=Inline builtin struct aref
before --jit: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6
) +JIT [x86_64-linux]
after --jit: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) +JIT [x86_64-linux]
last_commit=Inline builtin struct aref
Calculating -------------------------------------
before after before --jit after --jit
mjit_struct_aref(struct) 34.783M 34.810M 48.321M 58.378M i/s - 40.000M times in 1.149996s 1.149097s 0.827794s 0.685192s
Comparison:
mjit_struct_aref(struct)
after --jit: 58377836.7 i/s
before --jit: 48321205.7 i/s - 1.21x slower
after: 34809935.5 i/s - 1.68x slower
before: 34782736.5 i/s - 1.68x slower
```
2020-07-06 00:14:00 -07:00
Nobuyoshi Nakada
ccb7a4b9f2
Replaced accessors of `Struct` with `invokebuiltin`
2020-06-17 08:18:46 +09:00
Nobuyoshi Nakada
318d52e820
Revert "Replaced accessors of `Struct` with `invokebuiltin`"
...
This reverts commit 19cabe8b09
,
which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16 18:44:58 +09:00
Nobuyoshi Nakada
19cabe8b09
Replaced accessors of `Struct` with `invokebuiltin`
2020-06-16 18:24:02 +09:00
Nobuyoshi Nakada
8a504b224f
Added GC guard for splatted array
2020-05-08 21:23:21 +09:00