symbol_lookup 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/symbol_lookup/SymbolLookup.c +57 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8552cbf7c041894da45719e3a1251a4e274455d7
|
4
|
+
data.tar.gz: d4d3dcea61bd3241be9e8cecbf396eecbc434be2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a062b1bab8390e5656bb68f62cad16dad05b4f00d9dc8513674a83a396c3fa555f1a9dd150aaf2fe7002f6d97d0c7db65221805142d4cb1b7e94ae1c6cfd145
|
7
|
+
data.tar.gz: 78ae46266ac6c34f1e8e229191a676b5c08a7bde9a62e34d0400f4f531d10c5b3952082104e1d375fb479eeaccd6880520c59d1154cab2f33624dd3c0596ff41
|
@@ -16,11 +16,67 @@ sym_lookup(VALUE cls, VALUE str)
|
|
16
16
|
{
|
17
17
|
st_data_t id;
|
18
18
|
if (id = rb_check_id(&str)) {
|
19
|
-
|
19
|
+
return ID2SYM(id);
|
20
20
|
}
|
21
21
|
return Qnil;
|
22
22
|
}
|
23
23
|
|
24
|
+
/*
|
25
|
+
* call-seq:
|
26
|
+
* str.interned -> symbol
|
27
|
+
*
|
28
|
+
* Returns the <code>Symbol</code> corresponding to <i>str</i>, returning
|
29
|
+
* nil if it did not previously exist. See <code>Symbol[str]</code>.
|
30
|
+
*
|
31
|
+
* x = :banana
|
32
|
+
* "banana".interned #=> :banana
|
33
|
+
* "mango".interned #=> nil
|
34
|
+
*
|
35
|
+
*/
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
str_interned(VALUE str)
|
39
|
+
{
|
40
|
+
ID id;
|
41
|
+
|
42
|
+
if (id = rb_check_id(&str)) {
|
43
|
+
return ID2SYM(id);
|
44
|
+
}
|
45
|
+
return Qnil;
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* str.to_existing_sym -> symbol
|
51
|
+
*
|
52
|
+
* Returns the <code>Symbol</code> corresponding to <i>str</i>, raising an
|
53
|
+
* ArgumentError if it did not previously exist.
|
54
|
+
* See <code>Symbol[str]</code>
|
55
|
+
*
|
56
|
+
* x = :banana
|
57
|
+
* "banana".to_existing_sym #=> :banana
|
58
|
+
* "mango".to_existing_sym #=> (raises ArgumentError)
|
59
|
+
*
|
60
|
+
*/
|
61
|
+
|
62
|
+
VALUE
|
63
|
+
str_to_existing_sym(VALUE str)
|
64
|
+
{
|
65
|
+
ID id;
|
66
|
+
|
67
|
+
if (id = rb_check_id(&str)) {
|
68
|
+
return ID2SYM(id);
|
69
|
+
}
|
70
|
+
rb_raise(rb_eArgError, "undefined symbol :'%s'", StringValuePtr(str));
|
71
|
+
return Qnil;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
24
75
|
void Init_symbol_lookup() {
|
25
76
|
rb_define_singleton_method(rb_cSymbol, "[]", sym_lookup, 1);
|
77
|
+
rb_define_alias(rb_cSymbol, "interned", "intern");
|
78
|
+
rb_define_alias(rb_cSymbol, "to_existing_sym", "to_sym");
|
79
|
+
|
80
|
+
rb_define_method(rb_cString, "interned", str_interned, 0);
|
81
|
+
rb_define_method(rb_cString, "to_existing_sym", str_to_existing_sym, 0);
|
26
82
|
}
|
metadata
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symbol_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: |
|
14
|
+
A gemified version of the Symbol[str] method proposed in https://bugs.ruby-lang.org/issues/7854
|
15
|
+
|
16
|
+
Version 1.1.0 defines:
|
17
|
+
- Symbol[str] => Symbol or nil
|
18
|
+
- String#interned => Symbol or nil
|
19
|
+
- String#to_existing_sym => Symbol or exception
|
14
20
|
email: matthew@kerwin.net.au
|
15
21
|
executables: []
|
16
22
|
extensions:
|
@@ -46,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
52
|
version: '0'
|
47
53
|
requirements: []
|
48
54
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.0.
|
55
|
+
rubygems_version: 2.0.0
|
50
56
|
signing_key:
|
51
57
|
specification_version: 4
|
52
58
|
summary: Symbol[str]
|