final 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +12 -6
- data/{MANIFEST → MANIFEST.md} +3 -3
- data/README.md +69 -0
- data/Rakefile +2 -2
- data/final.gemspec +4 -9
- data/lib/final.rb +21 -22
- data/spec/final_spec.rb +1 -1
- metadata +11 -45
- metadata.gz.sig +0 -0
- data/README +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aabc866fcda14e6047d044a3bb77869df800f498db345807bd0793b187b1447a
|
4
|
+
data.tar.gz: 7dda6307af254464c9d1912b5a62adaaccd1990d8146d0f4f837d40716cec416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e0dafa040f9742dfe7a4b534048f4f9010b86afa4095d60c2584cf4ce78efc99d2829a59b18a257fd91e9e42d66e829f13594f6e1c3333d75b7f102f268d62
|
7
|
+
data.tar.gz: 14623815a23bc30fa4e27f4e21294869df88e8f21f1e267bafbd5d7ed61bddbeacb8b6a974bd0837760176750f9ae988520c3aae482036fcc3e00cca19367cd9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/{CHANGES → CHANGES.md}
RENAMED
@@ -1,22 +1,28 @@
|
|
1
|
-
|
1
|
+
## 0.3.1 - 7-Jun-2021
|
2
|
+
* Some internal refactoring to avoid string based instance_eval, plus
|
3
|
+
added some memoization. Thanks go to Okura Masafumi for the patch.
|
4
|
+
* Removed test-unit as a dev dependency, which I had apparently left
|
5
|
+
in the last release by mistake.
|
6
|
+
|
7
|
+
## 0.3.0 - 16-Sep-2020
|
2
8
|
* Switched from test-unit to rspec, and made corresponding updates.
|
3
9
|
|
4
|
-
|
10
|
+
## 0.2.1 - 1-Jun-2020
|
5
11
|
* Added a LICENSE file to distro as required by the Apache-2.0 license.
|
6
12
|
|
7
|
-
|
13
|
+
## 0.2.0 - 8-Jan-2019
|
8
14
|
* Changed license to Apache-2.0.
|
9
15
|
* The VERSION constant is now FINAL_VERSION since this is a module.
|
10
16
|
* Added some metadata to the gemspec.
|
11
17
|
* Updated the cert, should be good for about 10 years.
|
12
18
|
|
13
|
-
|
19
|
+
## 0.1.2 - 6-Dec-2015
|
14
20
|
* This gem is now signed.
|
15
21
|
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
16
22
|
|
17
|
-
|
23
|
+
## 0.1.1 - 8-Oct-2014
|
18
24
|
* Updated gemspec, removed references to RubyForge, etc.
|
19
25
|
* Updated Rakefile for Rubygems 2.x.
|
20
26
|
|
21
|
-
|
27
|
+
## 0.1.0 - 8-Apr-2011
|
22
28
|
* Initial release
|
data/{MANIFEST → MANIFEST.md}
RENAMED
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
[![Ruby](https://github.com/djberg96/final/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/final/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
## Description
|
4
|
+
A Ruby module that can make your classes final. A final class cannot
|
5
|
+
be subclassed, and its instance methods cannot be redefined.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
`gem install final`
|
9
|
+
|
10
|
+
## Synopsis
|
11
|
+
```ruby
|
12
|
+
require 'final'
|
13
|
+
|
14
|
+
class Alpha
|
15
|
+
include Final
|
16
|
+
|
17
|
+
def foo
|
18
|
+
puts "Hello"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Error! You cannot subclass Alpha.
|
23
|
+
class Beta < Alpha; end
|
24
|
+
|
25
|
+
# Error! You cannot redefine an existing method.
|
26
|
+
class Alpha
|
27
|
+
def foo
|
28
|
+
puts "Hi"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Not an error. You can add new methods to an existing class.
|
33
|
+
class Alpha
|
34
|
+
def bar
|
35
|
+
puts "World"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Developer's Notes
|
41
|
+
This library is merely a proof of concept that was published as the result
|
42
|
+
of a tweet made by James Edward Gray II, where he commented that Ruby core
|
43
|
+
classes should never be subclassed. Knowing that static languages like Java
|
44
|
+
implement the "final" keyword as a way to prevent subclassing, I wanted to
|
45
|
+
see if something similar could be done for Ruby. Turns out it can.
|
46
|
+
|
47
|
+
I do not, however, necessarily advocate actually using this library in
|
48
|
+
production code. Freezing a class this way is contrary to the very nature
|
49
|
+
of Ruby and dynamic languages in general. If you're going to use it, you had
|
50
|
+
better have a very good reason for doing so!
|
51
|
+
|
52
|
+
## Caveats
|
53
|
+
Only instance methods are prevented from redefinition. Singleton methods are
|
54
|
+
not final. This change may happen in a future release.
|
55
|
+
|
56
|
+
## License
|
57
|
+
Apache-2.0
|
58
|
+
|
59
|
+
## Copyright
|
60
|
+
(C) 2003-2021 Daniel J. Berger
|
61
|
+
All Rights Reserved.
|
62
|
+
|
63
|
+
## Warranty
|
64
|
+
This package is provided "as is" and without any express or
|
65
|
+
implied warranties, including, without limitation, the implied
|
66
|
+
warranties of merchantability and fitness for a particular purpose.
|
67
|
+
|
68
|
+
## Author
|
69
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -8,9 +8,9 @@ namespace :gem do
|
|
8
8
|
desc 'Build the final gem'
|
9
9
|
task :create => [:clean] do
|
10
10
|
require 'rubygems/package'
|
11
|
-
spec =
|
11
|
+
spec = Gem::Specification.load('final.gemspec')
|
12
12
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
13
|
-
Gem::Package.build(spec
|
13
|
+
Gem::Package.build(spec)
|
14
14
|
end
|
15
15
|
|
16
16
|
desc "Install the final gem"
|
data/final.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'final'
|
5
|
-
spec.version = '0.3.
|
5
|
+
spec.version = '0.3.1'
|
6
6
|
spec.license = 'Apache-2.0'
|
7
7
|
spec.author = 'Daniel J. Berger'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -12,15 +12,13 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
13
|
spec.cert_chain = Dir['certs/*']
|
14
14
|
|
15
|
-
spec.
|
16
|
-
|
17
|
-
spec.add_development_dependency "rake"
|
18
|
-
spec.add_development_dependency "rspec", "~> 3.9"
|
15
|
+
spec.add_development_dependency('rake')
|
16
|
+
spec.add_development_dependency('rspec', '~> 3.9')
|
19
17
|
|
20
18
|
spec.metadata = {
|
21
19
|
'homepage_uri' => 'https://github.com/djberg96/final',
|
22
20
|
'bug_tracker_uri' => 'https://github.com/djberg96/final/issues',
|
23
|
-
'changelog_uri' => 'https://github.com/djberg96/final/blob/
|
21
|
+
'changelog_uri' => 'https://github.com/djberg96/final/blob/main/CHANGES.md',
|
24
22
|
'documentation_uri' => 'https://github.com/djberg96/final/wiki',
|
25
23
|
'source_code_uri' => 'https://github.com/djberg96/final',
|
26
24
|
'wiki_uri' => 'https://github.com/djberg96/final/wiki'
|
@@ -30,7 +28,4 @@ Gem::Specification.new do |spec|
|
|
30
28
|
The final library enables you to declare your classes as final. This
|
31
29
|
prevents your class from being subclassed or having its methods redefined.
|
32
30
|
EOF
|
33
|
-
|
34
|
-
spec.add_development_dependency('rake')
|
35
|
-
spec.add_development_dependency('test-unit', '>= 2.2.0')
|
36
31
|
end
|
data/lib/final.rb
CHANGED
@@ -6,32 +6,31 @@ module Final
|
|
6
6
|
class Error < RuntimeError; end
|
7
7
|
|
8
8
|
# The version of the final library.
|
9
|
-
FINAL_VERSION = '0.3.
|
9
|
+
FINAL_VERSION = '0.3.1'.freeze
|
10
10
|
|
11
11
|
def self.included(mod)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@final_methods
|
18
|
-
end
|
12
|
+
mod.instance_eval do
|
13
|
+
# Store already defined methods.
|
14
|
+
def final_methods
|
15
|
+
@final_methods ||= []
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# Prevent subclassing, except implicity subclassing from Object.
|
19
|
+
def inherited(_sub)
|
20
|
+
raise Error, "cannot subclass #{self}" unless self == Object
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
# Prevent methods from being redefined.
|
24
|
+
#--
|
25
|
+
# There's still going to be a method redefinition warning. Gosh, it
|
26
|
+
# sure would be nice if we could disable warnings.
|
27
|
+
#
|
28
|
+
def method_added(sym)
|
29
|
+
if final_methods.include?(sym)
|
30
|
+
raise Error, "method '#{sym}' already defined"
|
31
|
+
else
|
32
|
+
final_methods << sym
|
33
|
+
end
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
data/spec/final_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: final
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
@@ -65,65 +65,31 @@ dependencies:
|
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '3.9'
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: rake
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
type: :development
|
76
|
-
prerelease: false
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: test-unit
|
84
|
-
requirement: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 2.2.0
|
89
|
-
type: :development
|
90
|
-
prerelease: false
|
91
|
-
version_requirements: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 2.2.0
|
96
68
|
description: |2
|
97
69
|
The final library enables you to declare your classes as final. This
|
98
70
|
prevents your class from being subclassed or having its methods redefined.
|
99
71
|
email: djberg96@gmail.com
|
100
72
|
executables: []
|
101
73
|
extensions: []
|
102
|
-
extra_rdoc_files:
|
103
|
-
- README
|
104
|
-
- CHANGES
|
105
|
-
- MANIFEST
|
74
|
+
extra_rdoc_files: []
|
106
75
|
files:
|
76
|
+
- CHANGES.md
|
77
|
+
- Gemfile
|
107
78
|
- LICENSE
|
108
|
-
-
|
109
|
-
-
|
110
|
-
- spec
|
111
|
-
- spec/final_spec.rb
|
112
|
-
- README
|
79
|
+
- MANIFEST.md
|
80
|
+
- README.md
|
113
81
|
- Rakefile
|
114
|
-
- certs
|
115
82
|
- certs/djberg96_pub.pem
|
116
|
-
- lib
|
117
|
-
- lib/final.rb
|
118
|
-
- Gemfile
|
119
83
|
- final.gemspec
|
84
|
+
- lib/final.rb
|
85
|
+
- spec/final_spec.rb
|
120
86
|
homepage: https://github.com/djberg96/final
|
121
87
|
licenses:
|
122
88
|
- Apache-2.0
|
123
89
|
metadata:
|
124
90
|
homepage_uri: https://github.com/djberg96/final
|
125
91
|
bug_tracker_uri: https://github.com/djberg96/final/issues
|
126
|
-
changelog_uri: https://github.com/djberg96/final/blob/
|
92
|
+
changelog_uri: https://github.com/djberg96/final/blob/main/CHANGES.md
|
127
93
|
documentation_uri: https://github.com/djberg96/final/wiki
|
128
94
|
source_code_uri: https://github.com/djberg96/final
|
129
95
|
wiki_uri: https://github.com/djberg96/final/wiki
|
@@ -142,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
108
|
- !ruby/object:Gem::Version
|
143
109
|
version: '0'
|
144
110
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.2.15
|
146
112
|
signing_key:
|
147
113
|
specification_version: 4
|
148
114
|
summary: An implementation of 'final' for Ruby
|
metadata.gz.sig
CHANGED
Binary file
|
data/README
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
A Ruby module that can make your classes final. A final class cannot
|
3
|
-
be subclassed, and its instance methods cannot be redefined.
|
4
|
-
|
5
|
-
= Installation
|
6
|
-
gem install final
|
7
|
-
|
8
|
-
= Synopsis
|
9
|
-
require 'final'
|
10
|
-
|
11
|
-
class Alpha
|
12
|
-
include Final
|
13
|
-
|
14
|
-
def foo
|
15
|
-
puts "Hello"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Error! You cannot subclass Alpha.
|
20
|
-
class Beta < Alpha; end
|
21
|
-
|
22
|
-
# Error! You cannot redefine an existing method.
|
23
|
-
class Alpha
|
24
|
-
def foo
|
25
|
-
puts "Hi"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Not an error. You can add new methods to an existing class.
|
30
|
-
class Alpha
|
31
|
-
def bar
|
32
|
-
puts "World"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
= Developer's Notes
|
37
|
-
This library is merely a proof of concept that was published as the result
|
38
|
-
of a tweet made by James Edward Gray II, where he commented that Ruby core
|
39
|
-
classes should never be subclassed. Knowing that static languages like Java
|
40
|
-
implement the "final" keyword as a way to prevent subclassing, I wanted to
|
41
|
-
see if something similar could be done for Ruby. Turns out it can.
|
42
|
-
|
43
|
-
I do not, however, necessarily advocate actually using this library in
|
44
|
-
production code. Freezing a class this way is contrary to the very nature
|
45
|
-
of Ruby and dynamic languages in general. If you're going to use it, you had
|
46
|
-
better have a very good reason for doing so!
|
47
|
-
|
48
|
-
= Caveats
|
49
|
-
Only instance methods are prevented from redefinition. Singleton methods are
|
50
|
-
not final. This change may happen in a future release.
|
51
|
-
|
52
|
-
= License
|
53
|
-
Apache-2.0
|
54
|
-
|
55
|
-
= Copyright
|
56
|
-
(C) 2003-2019 Daniel J. Berger
|
57
|
-
All Rights Reserved.
|
58
|
-
|
59
|
-
= Warranty
|
60
|
-
This package is provided "as is" and without any express or
|
61
|
-
implied warranties, including, without limitation, the implied
|
62
|
-
warranties of merchantability and fitness for a particular purpose.
|
63
|
-
|
64
|
-
= Author
|
65
|
-
Daniel J. Berger
|