kernel-symbol 1.0.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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +78 -0
- data/lib/kernel/symbol.rb +27 -0
- data/lib/kernel.rb +7 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5160e8719a7e326f8bfe104b6f710297b5c694183857c00caf3599d8618bf619
|
4
|
+
data.tar.gz: fbdd1e308c62734b05acd15cc3ac9c56990712d7cfc2c5cf6372441adfbe36cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 492a7fee4c7b1358c1f03debd8d9809164aec438fc35a5a0c585e997734e12b7356ec1e7c58a060713a4eadb057c8f21810fbd1ef371440e9bfafe08af4db001
|
7
|
+
data.tar.gz: ea21d87c2c79f076eb190e0823ac1cfe0b53176abcbdd1090e64b5d67f7933553a3684a529c6e63002aa6c86b258d7ee56a17ef150a3bebc3a657f04a93aab69
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Cyril Kato
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# `Kernel#Symbol`
|
2
|
+
|
3
|
+
Returns a `Symbol` based on the given argument.
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[](https://github.com/cyril/kernel-symbol.rb/tags)
|
8
|
+
[](https://rubydoc.info/github/cyril/kernel-symbol.rb/main)
|
9
|
+
[](https://github.com/cyril/kernel-symbol.rb/actions?query=workflow%3Aruby+branch%3Amain)
|
10
|
+
[](https://github.com/cyril/kernel-symbol.rb/actions?query=workflow%3Arubocop+branch%3Amain)
|
11
|
+
[](https://github.com/cyril/kernel-symbol.rb/raw/main/LICENSE.md)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem "kernel-symbol"
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
bundle install
|
25
|
+
```
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
gem install kernel-symbol
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
If the argument is a symbol, returns the symbol.
|
36
|
+
If the argument is not a symbol, tries to convert to a symbol.
|
37
|
+
|
38
|
+
In all other cases, returns an error.
|
39
|
+
|
40
|
+
### Example
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require "kernel/symbol"
|
44
|
+
|
45
|
+
Symbol(:foo) # => :foo
|
46
|
+
Symbol("foo") # => :foo
|
47
|
+
Symbol(true) # => :true
|
48
|
+
Symbol(42) # => :"42"
|
49
|
+
Symbol(BasicObject.new) # TypeError (can't convert BasicObject into String)
|
50
|
+
```
|
51
|
+
|
52
|
+
### Note
|
53
|
+
|
54
|
+
The `#Symbol` method could be used similarly to the methods already present in the `Kernel` module:
|
55
|
+
|
56
|
+
* `#Array`
|
57
|
+
* `#Complex`
|
58
|
+
* `#Float`
|
59
|
+
* `#Hash`
|
60
|
+
* `#Integer`
|
61
|
+
* `#Rational`
|
62
|
+
* `#String`
|
63
|
+
|
64
|
+
### Warning
|
65
|
+
|
66
|
+
The `Kernel` module is included in the `Object` class, so by loading this library, the `#Symbol` method will be available in every Ruby object.
|
67
|
+
|
68
|
+
## Versioning
|
69
|
+
|
70
|
+
`Kernel#Symbol` uses [Semantic Versioning 2.0.0](https://semver.org/)
|
71
|
+
|
72
|
+
## See also
|
73
|
+
|
74
|
+
* [`kernel-boolean`](https://github.com/cyril/kernel-boolean.rb): Returns a `Boolean` based on the given argument.
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
The [gem](https://rubygems.org/gems/kernel-symbol) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The Kernel module.
|
4
|
+
module Kernel
|
5
|
+
# rubocop:disable Naming/MethodName
|
6
|
+
|
7
|
+
# @note Converts _arg_ to a string and then converts the string to a symbol.
|
8
|
+
#
|
9
|
+
# @param arg [#object_id] An object.
|
10
|
+
#
|
11
|
+
# @return [Symbol] Returns _arg_ as a `Symbol`.
|
12
|
+
#
|
13
|
+
# @raise [ArgumentError, TypeError] Not conform with symbol representation.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# require "kernel/symbol"
|
17
|
+
#
|
18
|
+
# Symbol(:foo) # => :foo
|
19
|
+
# Symbol("foo") # => :foo
|
20
|
+
# Symbol(true) # => :true
|
21
|
+
# Symbol(42) # => :"42"
|
22
|
+
# Symbol(BasicObject.new) # TypeError (can't convert BasicObject into String)
|
23
|
+
def Symbol(arg)
|
24
|
+
:"#{String(arg)}"
|
25
|
+
end
|
26
|
+
# rubocop:enable Naming/MethodName
|
27
|
+
end
|
data/lib/kernel.rb
ADDED
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kernel-symbol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyril Kato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: r_spec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-gitlab-security
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-md
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-thread_safety
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Returns a symbol based on the given argument.
|
168
|
+
email: contact@cyril.email
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- LICENSE.md
|
174
|
+
- README.md
|
175
|
+
- lib/kernel.rb
|
176
|
+
- lib/kernel/symbol.rb
|
177
|
+
homepage: https://github.com/cyril/kernel-symbol.rb
|
178
|
+
licenses:
|
179
|
+
- MIT
|
180
|
+
metadata:
|
181
|
+
rubygems_mfa_required: 'true'
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 2.7.0
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
requirements: []
|
197
|
+
rubygems_version: 3.1.6
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Returns a symbol based on the given argument.
|
201
|
+
test_files: []
|