attic 0.5.3 → 0.6.pre.RC1
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/{README.rdoc → README.md} +21 -15
- data/Rakefile +6 -37
- data/attic.gemspec +13 -45
- data/lib/attic.rb +64 -63
- metadata +34 -67
- data/CHANGES.txt +0 -48
- data/LICENSE.txt +0 -19
- data/try/01_mixins_tryouts.rb +0 -17
- data/try/10_attic_tryouts.rb +0 -41
- data/try/20_accessing_tryouts.rb +0 -29
- data/try/25_string_tryouts.rb +0 -32
- data/try/30_nometaclass_tryouts.rb +0 -51
- data/try/40_explicit_accessor_tryouts.rb +0 -17
- data/try/X1_metaclasses.rb +0 -112
- data/try/X2_extending.rb +0 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cab1b37cf99fda2d7f47b898c998af908e2c8f4dcdde31ae66cd34d7c337a993
|
4
|
+
data.tar.gz: 7d579f1320f3493b6639705d316aaf1197f77aa20894ecff84abd0a34a162124
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 920f145e1b3eb27151653a69be076fe3224c82e2781695209e2017ac4634708855dc0331ad254a9765bd185f25e566b1c6a712bc6118668c201ec0fa240239fc
|
7
|
+
data.tar.gz: e0e4204bd76ae3f76c7c3a51166c278f69b2152db651a2ccd28ce8d559f281bfbf18e253713608fad2d9d488b96f52d3397070de7cc606842c3f47971db1276a
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,48 +1,54 @@
|
|
1
|
-
|
1
|
+
# Attic - v0.6-RC1 (2021-07-01)
|
2
2
|
|
3
3
|
A place to hide private instance variables in your Ruby objects.
|
4
4
|
|
5
|
-
|
5
|
+
## Example
|
6
6
|
|
7
|
+
```ruby
|
7
8
|
require 'attic'
|
8
|
-
|
9
|
+
|
9
10
|
class String
|
10
11
|
extend Attic
|
11
12
|
attic :timestamp
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
a = "anything"
|
15
16
|
a.timestamp = "1980-11-18"
|
16
17
|
a.instance_variables # => []
|
17
18
|
a.timestamp # 1980-11-18
|
18
|
-
|
19
|
+
|
19
20
|
a.attic_variables # => [:timestamp]
|
20
|
-
|
21
|
+
|
21
22
|
a.attic_variable_set :tags, [:a, :b, :c]
|
22
23
|
a.attic_variable_get :tags # [:a, :b, :c]
|
23
|
-
|
24
|
+
|
24
25
|
a.attic_variables # => [:timestamp, :tags]
|
25
|
-
|
26
|
-
|
26
|
+
```
|
27
|
+
|
28
|
+
## Some objects have no metaclasses
|
27
29
|
|
28
|
-
Symbol
|
30
|
+
Symbol objects do not have metaclasses so instance variables are hidden in the object itself.
|
29
31
|
|
30
32
|
|
31
|
-
|
33
|
+
## Installation
|
32
34
|
|
33
35
|
Via Rubygems, one of:
|
34
36
|
|
37
|
+
```shell
|
35
38
|
$ gem install attic
|
39
|
+
```
|
36
40
|
|
37
41
|
or via download:
|
38
42
|
* attic-latest.tar.gz[http://github.com/delano/attic/tarball/latest]
|
39
43
|
* attic-latest.zip[http://github.com/delano/attic/zipball/latest]
|
40
44
|
|
41
45
|
|
42
|
-
|
46
|
+
## Credits
|
47
|
+
|
48
|
+
* `gems@solutious.com` (@delano)
|
49
|
+
|
43
50
|
|
44
|
-
|
51
|
+
## License
|
45
52
|
|
46
|
-
|
53
|
+
MIT
|
47
54
|
|
48
|
-
See: LICENSE.txt
|
data/Rakefile
CHANGED
@@ -1,25 +1,16 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rubygems/package_task'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'rdoc/task'
|
5
6
|
include FileUtils
|
6
|
-
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'hanna/rdoctask'
|
10
|
-
rescue LoadError
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
end
|
13
|
-
|
14
7
|
|
15
8
|
task :default => :package
|
16
|
-
|
9
|
+
|
17
10
|
# CONFIG =============================================================
|
18
11
|
|
19
12
|
# Change the following according to your needs
|
20
|
-
README = "README.
|
21
|
-
CHANGES = "CHANGES.txt"
|
22
|
-
LICENSE = "LICENSE.txt"
|
13
|
+
README = "README.md"
|
23
14
|
|
24
15
|
# Files and directories to be deleted when you run "rake clean"
|
25
16
|
CLEAN.include [ 'pkg', '*.gem', '.config']
|
@@ -30,7 +21,7 @@ load "#{name}.gemspec"
|
|
30
21
|
version = @spec.version
|
31
22
|
|
32
23
|
# That's it! The following defaults should allow you to get started
|
33
|
-
# on other things.
|
24
|
+
# on other things.
|
34
25
|
|
35
26
|
|
36
27
|
# TESTS/SPECS =========================================================
|
@@ -39,7 +30,7 @@ version = @spec.version
|
|
39
30
|
|
40
31
|
# INSTALL =============================================================
|
41
32
|
|
42
|
-
|
33
|
+
Gem::PackageTask.new(@spec) do |p|
|
43
34
|
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
44
35
|
end
|
45
36
|
|
@@ -52,25 +43,6 @@ task :uninstall => [ :clean ] do
|
|
52
43
|
end
|
53
44
|
|
54
45
|
|
55
|
-
# RUBYFORGE RELEASE / PUBLISH TASKS ==================================
|
56
|
-
|
57
|
-
if @spec.rubyforge_project
|
58
|
-
desc 'Publish website to rubyforge'
|
59
|
-
task 'publish:rdoc' => 'doc/index.html' do
|
60
|
-
sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
|
61
|
-
end
|
62
|
-
|
63
|
-
desc 'Public release to rubyforge'
|
64
|
-
task 'publish:gem' => [:package] do |t|
|
65
|
-
sh <<-end
|
66
|
-
rubyforge add_release -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
|
67
|
-
rubyforge add_file -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
46
|
# RUBY DOCS TASK ==================================
|
75
47
|
|
76
48
|
Rake::RDocTask.new do |t|
|
@@ -78,10 +50,7 @@ Rake::RDocTask.new do |t|
|
|
78
50
|
t.title = @spec.summary
|
79
51
|
t.options << '--line-numbers' << '-A cattr_accessor=object'
|
80
52
|
t.options << '--charset' << 'utf-8'
|
81
|
-
t.rdoc_files.include(LICENSE)
|
82
53
|
t.rdoc_files.include(README)
|
83
|
-
t.rdoc_files.include(CHANGES)
|
84
|
-
#t.rdoc_files.include('bin/*')
|
85
54
|
t.rdoc_files.include('lib/**/*.rb')
|
86
55
|
end
|
87
56
|
|
data/attic.gemspec
CHANGED
@@ -1,52 +1,20 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "attic"
|
3
|
-
|
4
|
-
s.
|
5
|
-
s.
|
6
|
-
s.description = s.summary
|
3
|
+
s.version = "0.6-RC1"
|
4
|
+
s.summary = "When in doubt, store it in the attic"
|
5
|
+
s.description = "Attic: a place to hide metadata about the class or variable itself (e.g. SHA hash summaries)."
|
7
6
|
s.author = "Delano Mandelbaum"
|
8
|
-
s.email = "
|
7
|
+
s.email = "gems@solutious.com"
|
9
8
|
s.homepage = "http://github.com/delano/attic"
|
10
|
-
|
11
|
-
# = EXECUTABLES =
|
12
|
-
# The list of executables in your project (if any). Don't include the path,
|
13
|
-
# just the base filename.
|
14
9
|
s.executables = %w[]
|
15
|
-
|
16
|
-
|
17
|
-
s.
|
18
|
-
|
19
|
-
# Specific files to include rdocs from
|
20
|
-
s.extra_rdoc_files = %w[README.rdoc LICENSE.txt CHANGES.txt]
|
21
|
-
|
22
|
-
# Update --main to reflect the default page to display
|
23
|
-
s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
|
24
|
-
|
25
|
-
# = MANIFEST =
|
26
|
-
# The complete list of files to be included in the release. When GitHub packages your gem,
|
27
|
-
# it doesn't allow you to run any command that accesses the filesystem. You will get an
|
28
|
-
# error. You can ask your VCS for the list of versioned files:
|
29
|
-
# git ls-files
|
30
|
-
# svn list -R
|
10
|
+
s.require_paths = %w[lib]
|
11
|
+
s.extra_rdoc_files = %w[README.md]
|
12
|
+
s.licenses = ["MIT"] # https://spdx.org/licenses/MIT-Modern-Variant.html
|
13
|
+
s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.md"]
|
31
14
|
s.files = %w(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
attic.gemspec
|
37
|
-
lib/attic.rb
|
38
|
-
try/01_mixins_tryouts.rb
|
39
|
-
try/10_attic_tryouts.rb
|
40
|
-
try/20_accessing_tryouts.rb
|
41
|
-
try/25_string_tryouts.rb
|
42
|
-
try/30_nometaclass_tryouts.rb
|
43
|
-
try/40_explicit_accessor_tryouts.rb
|
44
|
-
try/X1_metaclasses.rb
|
45
|
-
try/X2_extending.rb
|
15
|
+
README.md
|
16
|
+
Rakefile
|
17
|
+
attic.gemspec
|
18
|
+
lib/attic.rb
|
46
19
|
)
|
47
|
-
|
48
|
-
s.has_rdoc = true
|
49
|
-
s.rubygems_version = '1.3.0'
|
50
|
-
|
51
|
-
|
52
|
-
end
|
20
|
+
end
|
data/lib/attic.rb
CHANGED
@@ -4,80 +4,96 @@ end
|
|
4
4
|
|
5
5
|
# = Object
|
6
6
|
#
|
7
|
-
# These methods are copied directly from _why's metaid.rb.
|
7
|
+
# These methods are copied directly from _why's metaid.rb.
|
8
8
|
# See: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
|
9
9
|
class Object
|
10
|
-
|
10
|
+
|
11
11
|
unless defined?(::Object::NOMETACLASS)
|
12
12
|
# An Array of classes which do not have metaclasses.
|
13
|
-
NOMETACLASS = [Symbol,
|
13
|
+
NOMETACLASS = [Symbol, Integer]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def nometaclass?
|
17
17
|
NOMETACLASS.member?(self)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def metaclass?
|
21
21
|
!NOMETACLASS.member?(self.class)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# A convenient method for getting the metaclass of the current object.
|
25
25
|
# i.e.
|
26
26
|
#
|
27
27
|
# class << self; self; end;
|
28
28
|
#
|
29
|
-
# NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
|
29
|
+
# NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
|
30
30
|
# For these classes, this method returns the class itself. That means
|
31
|
-
# the instance variables will stored in the class itself.
|
31
|
+
# the instance variables will be stored in the class itself.
|
32
32
|
def metaclass
|
33
|
-
if
|
34
|
-
|
33
|
+
if self.metaclass?
|
34
|
+
class << self
|
35
|
+
self
|
36
|
+
end
|
35
37
|
else
|
36
|
-
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def metaclassfly
|
43
|
+
location = self.class
|
44
|
+
attr_name = "@@_attic_#{self.object_id}"
|
45
|
+
unless location.class_variable_defined? attr_name
|
46
|
+
location.class_variable_set attr_name, Class.new
|
37
47
|
end
|
48
|
+
location.class_variable_get attr_name
|
38
49
|
end
|
39
|
-
|
50
|
+
|
40
51
|
# Execute a block +&blk+ within the metaclass of the current object.
|
41
|
-
def meta_eval &blk
|
42
|
-
|
52
|
+
def meta_eval &blk
|
53
|
+
metaclass.instance_eval blk
|
54
|
+
end
|
55
|
+
|
43
56
|
# Add an instance method called +name+ to metaclass for the current object.
|
44
57
|
# This is useful because it will be available as a singleton method
|
45
|
-
# to all subclasses too.
|
58
|
+
# to all subclasses too.
|
46
59
|
def meta_def name, &blk
|
47
60
|
meta_eval { define_method name, &blk }
|
48
61
|
end
|
49
|
-
|
62
|
+
|
50
63
|
# Add a class method called +name+ for the current object's class. This
|
51
|
-
# isn't so special but it maintains consistency with meta_def.
|
64
|
+
# isn't so special but it maintains consistency with meta_def.
|
52
65
|
def class_def name, &blk
|
53
66
|
class_eval { define_method name, &blk }
|
54
67
|
end
|
55
68
|
|
56
|
-
|
69
|
+
|
57
70
|
# A convenient method for getting the metaclass of the metaclass
|
58
71
|
# i.e.
|
59
72
|
#
|
60
73
|
# self.metaclass.metaclass
|
61
74
|
#
|
62
|
-
def metametaclass
|
75
|
+
def metametaclass
|
76
|
+
self.metaclass.metaclass
|
77
|
+
end
|
63
78
|
|
64
|
-
def metameta_eval &blk
|
79
|
+
def metameta_eval &blk
|
80
|
+
metametaclass.instance_eval blk
|
81
|
+
end
|
65
82
|
|
66
83
|
def metameta_def name, &blk
|
67
84
|
metameta_eval { define_method name, &blk }
|
68
85
|
end
|
69
|
-
|
70
86
|
end
|
71
87
|
|
72
88
|
|
73
89
|
|
74
90
|
# = Attic
|
75
91
|
#
|
76
|
-
# A place to store instance variables.
|
92
|
+
# A place to store instance variables.
|
77
93
|
#
|
78
94
|
module Attic
|
79
|
-
VERSION = '0.
|
80
|
-
|
95
|
+
VERSION = '0.6-RC1' unless defined?(VERSION)
|
96
|
+
|
81
97
|
module InstanceMethods
|
82
98
|
def attic_variables
|
83
99
|
self.class.attic_variables
|
@@ -88,43 +104,31 @@ module Attic
|
|
88
104
|
end
|
89
105
|
def attic_variable_set(n,v)
|
90
106
|
attic_variables << n unless attic_variable? n
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
instance_variable_set("@___attic_#{n}", v)
|
95
|
-
end
|
107
|
+
# binding.pry
|
108
|
+
metaclassfly.instance_variable_set("@___attic_#{n}", v)
|
96
109
|
end
|
97
110
|
def attic_variable_get(n)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
111
|
+
metaclassfly.instance_variable_get("@___attic_#{n}")
|
112
|
+
end
|
113
|
+
def get_binding
|
114
|
+
binding
|
103
115
|
end
|
104
116
|
end
|
105
|
-
|
117
|
+
|
106
118
|
def self.included(o)
|
107
119
|
raise "You probably meant to 'extend Attic' in #{o}"
|
108
120
|
end
|
109
|
-
|
121
|
+
|
110
122
|
def self.extended(o)
|
111
|
-
# This class has already been extended.
|
123
|
+
# This class has already been extended.
|
112
124
|
return if o.ancestors.member? Attic::InstanceMethods
|
113
|
-
|
114
|
-
|
115
|
-
## NOTE: This is just a reminder for a more descerning way to
|
116
|
-
## include the meta methods, instead of using a global mixin.
|
117
|
-
##o.class_eval do
|
118
|
-
## include ObjectHelpers
|
119
|
-
##end
|
120
|
-
# Create an instance method that returns the attic variables.
|
125
|
+
|
126
|
+
# Add the instance methods for accessing attic variables
|
121
127
|
o.send :include, Attic::InstanceMethods
|
122
|
-
|
123
|
-
|
128
|
+
|
124
129
|
o.metaclass.instance_variable_set("@attic_variables", [])
|
125
130
|
o.class_eval do
|
126
131
|
def self.inherited(o2)
|
127
|
-
#p [:inherit, self, o2]
|
128
132
|
attic_vars = self.attic_variables.clone
|
129
133
|
o2.metaclass.instance_variable_set("@attic_variables", attic_vars)
|
130
134
|
end
|
@@ -140,20 +144,17 @@ module Attic
|
|
140
144
|
end
|
141
145
|
end
|
142
146
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
#
|
149
|
-
# * +junk+ is a list of variables names. Accessor methods are
|
150
|
-
# created for each variable name in the list.
|
151
|
-
#
|
147
|
+
end
|
148
|
+
|
149
|
+
# A class method for defining variables to store in the attic.
|
150
|
+
# * +junk+ is a list of variables names. Accessor methods are
|
151
|
+
# created for each variable name in the list.
|
152
|
+
#
|
152
153
|
# Returns the list of attic variable names or if not junk was
|
153
|
-
# given, returns the metaclass.
|
154
|
+
# given, returns the metaclass.
|
154
155
|
#
|
155
156
|
# e.g.
|
156
|
-
#
|
157
|
+
#
|
157
158
|
# String.extend Attic
|
158
159
|
# String.attic :timestamp
|
159
160
|
#
|
@@ -166,7 +167,7 @@ module Attic
|
|
166
167
|
junk.each do |name|
|
167
168
|
next if attic_variable? name
|
168
169
|
self.attic_variables << name
|
169
|
-
|
170
|
+
|
170
171
|
unless method_defined? name
|
171
172
|
define_method(name) do
|
172
173
|
attic_variable_get name
|
@@ -180,8 +181,8 @@ module Attic
|
|
180
181
|
end
|
181
182
|
attic_vars
|
182
183
|
end
|
183
|
-
|
184
|
-
# Returns an Array of attic variables for the current class.
|
184
|
+
|
185
|
+
# Returns an Array of attic variables for the current class.
|
185
186
|
# e.g.
|
186
187
|
#
|
187
188
|
# String.extend Attic
|
@@ -198,7 +199,7 @@ module Attic
|
|
198
199
|
def attic_variable?(n)
|
199
200
|
attic_variables.member? n
|
200
201
|
end
|
201
|
-
|
202
|
+
|
202
203
|
end
|
203
204
|
|
204
205
|
# - Module#instance_method returns an UnboundMethod
|
metadata
CHANGED
@@ -1,86 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: attic
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 3
|
10
|
-
version: 0.5.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.pre.RC1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Delano Mandelbaum
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-02-11 00:00:00 -05:00
|
19
|
-
default_executable:
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
20
12
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
email:
|
13
|
+
description: 'Attic: a place to hide metadata about the class or variable itself (e.g.
|
14
|
+
SHA hash summaries).'
|
15
|
+
email: gems@solutious.com
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
- CHANGES.txt
|
32
|
-
files:
|
33
|
-
- CHANGES.txt
|
34
|
-
- LICENSE.txt
|
35
|
-
- README.rdoc
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.md
|
20
|
+
files:
|
21
|
+
- README.md
|
36
22
|
- Rakefile
|
37
23
|
- attic.gemspec
|
38
24
|
- lib/attic.rb
|
39
|
-
- try/01_mixins_tryouts.rb
|
40
|
-
- try/10_attic_tryouts.rb
|
41
|
-
- try/20_accessing_tryouts.rb
|
42
|
-
- try/25_string_tryouts.rb
|
43
|
-
- try/30_nometaclass_tryouts.rb
|
44
|
-
- try/40_explicit_accessor_tryouts.rb
|
45
|
-
- try/X1_metaclasses.rb
|
46
|
-
- try/X2_extending.rb
|
47
|
-
has_rdoc: true
|
48
25
|
homepage: http://github.com/delano/attic
|
49
|
-
licenses:
|
50
|
-
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
51
29
|
post_install_message:
|
52
|
-
rdoc_options:
|
53
|
-
- --line-numbers
|
54
|
-
- --title
|
55
|
-
-
|
56
|
-
- --main
|
57
|
-
- README.
|
58
|
-
require_paths:
|
30
|
+
rdoc_options:
|
31
|
+
- "--line-numbers"
|
32
|
+
- "--title"
|
33
|
+
- When in doubt, store it in the attic
|
34
|
+
- "--main"
|
35
|
+
- README.md
|
36
|
+
require_paths:
|
59
37
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
|
62
|
-
requirements:
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
63
40
|
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 3
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.1
|
78
48
|
requirements: []
|
79
|
-
|
80
|
-
rubyforge_project: attic
|
81
|
-
rubygems_version: 1.5.2
|
49
|
+
rubygems_version: 3.2.21
|
82
50
|
signing_key:
|
83
|
-
specification_version:
|
84
|
-
summary:
|
51
|
+
specification_version: 4
|
52
|
+
summary: When in doubt, store it in the attic
|
85
53
|
test_files: []
|
86
|
-
|
data/CHANGES.txt
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
ATTIC, CHANGES
|
2
|
-
|
3
|
-
#### 0.5.3 (2011-02-11) ###############################
|
4
|
-
|
5
|
-
* FIXED: Don't redefine Object::NOMETACLASS
|
6
|
-
* CHANGE: Updated tests to Tryouts 2
|
7
|
-
* CHANGE: Move attic/mixins content to attic.rb
|
8
|
-
|
9
|
-
|
10
|
-
#### 0.5.2 (2010-02-15) ###############################
|
11
|
-
|
12
|
-
* CHANGE: Remove hanna dependency [Diego Elio 'Flameeyes' Pettenò]
|
13
|
-
|
14
|
-
#### 0.5.0 (2009-11-29) ###############################
|
15
|
-
|
16
|
-
* FIXED: Classes can now only be extended once
|
17
|
-
* FIXED: Don't define the same attic variable more then once
|
18
|
-
* FIXED: Don't define instance_variable method for objects which
|
19
|
-
don't already have one.
|
20
|
-
* CHANGE: attic_vars method is now attic_variables
|
21
|
-
* CHANGE: Won't define accessor methods if methods with the same
|
22
|
-
name already exist.
|
23
|
-
* ADDED: all_instance_variables method (for no metaclasses)
|
24
|
-
* ADDED: Explicit attic_variable_set and attic_variable_get methods
|
25
|
-
|
26
|
-
|
27
|
-
#### 0.4.0 (2009-07-17) ###############################
|
28
|
-
|
29
|
-
* ADDED: Support for objects that don't have metaclasses:
|
30
|
-
Currently: Symbols, Fixnum
|
31
|
-
* CHANGE: Objects with no metaclass raise NoMetaClass exception.
|
32
|
-
|
33
|
-
|
34
|
-
#### 0.3.1 (2009-07-13) ###############################
|
35
|
-
|
36
|
-
CRIPES! I'd forgotten to update the gemspec.
|
37
|
-
|
38
|
-
#### 0.3 (2009-07-11) ###############################
|
39
|
-
|
40
|
-
NOTE: A complete re-write from 0.2
|
41
|
-
|
42
|
-
* FIXED: Now works on any Object except Symbol and Fixnum
|
43
|
-
* ADDED: attic_vars method
|
44
|
-
|
45
|
-
|
46
|
-
#### 0.2 (2009-07-08) ###############################
|
47
|
-
|
48
|
-
NOTE: Initial public release
|
data/LICENSE.txt
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 Solutious Inc, Delano Mandelbaum
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/try/01_mixins_tryouts.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
|
3
|
-
## has metaclass", 'Object' do
|
4
|
-
if Tryouts.sysinfo.ruby.to_s == "1.9.1"
|
5
|
-
Object.new.metaclass.superclass.to_s
|
6
|
-
else
|
7
|
-
'Object'
|
8
|
-
end
|
9
|
-
#=> 'Object'
|
10
|
-
|
11
|
-
## has metametaclass", '#<Class:Object>' do
|
12
|
-
if Tryouts.sysinfo.ruby.to_s >= "1.9.1"
|
13
|
-
Object.new.metaclass.superclass.to_s
|
14
|
-
else
|
15
|
-
'#<Class:Object>'
|
16
|
-
end
|
17
|
-
#=> 'Object'
|
data/try/10_attic_tryouts.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
|
3
|
-
## can extend Attic
|
4
|
-
class ::Worker
|
5
|
-
extend Attic
|
6
|
-
def kind() :true end
|
7
|
-
end
|
8
|
-
# 1.9 # 1.8
|
9
|
-
Worker.methods.member?(:attic) || Worker.methods.member?('attic')
|
10
|
-
#=> true
|
11
|
-
|
12
|
-
## can't include Attic raises exception
|
13
|
-
begin
|
14
|
-
class ::Worker
|
15
|
-
include Attic
|
16
|
-
end
|
17
|
-
rescue => RuntimeError
|
18
|
-
:success
|
19
|
-
end
|
20
|
-
#=> :success
|
21
|
-
|
22
|
-
## can define attic attribute
|
23
|
-
Worker.attic :size
|
24
|
-
w = Worker.new
|
25
|
-
#w.attic :size
|
26
|
-
p Worker.instance_methods(false)
|
27
|
-
p Worker.methods.sort
|
28
|
-
w.respond_to? :size
|
29
|
-
#=> true
|
30
|
-
|
31
|
-
## can access attic attributes explicitly"
|
32
|
-
w = Worker.new
|
33
|
-
w.attic_variable_set :size, 2
|
34
|
-
w.attic_variable_get :size
|
35
|
-
#=> 2
|
36
|
-
|
37
|
-
## won't define a method if on already exists
|
38
|
-
Worker.attic :kind
|
39
|
-
a = Worker.new
|
40
|
-
a.kind
|
41
|
-
#=> :true
|
data/try/20_accessing_tryouts.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
class ::Worker
|
3
|
-
extend Attic
|
4
|
-
attic :size
|
5
|
-
end
|
6
|
-
|
7
|
-
|
8
|
-
## save an instance variable the long way
|
9
|
-
w = Worker.new
|
10
|
-
w.metametaclass.instance_variable_set '@mattress', 'S&F'
|
11
|
-
w.metametaclass.instance_variable_get '@mattress'
|
12
|
-
#=> 'S&F'
|
13
|
-
|
14
|
-
## save an instance variable the short way
|
15
|
-
w = Worker.new
|
16
|
-
w.size = :california_king
|
17
|
-
w.size
|
18
|
-
#=> :california_king
|
19
|
-
|
20
|
-
## new instances don't cross streams
|
21
|
-
w = Worker.new
|
22
|
-
w.size
|
23
|
-
#=> nil
|
24
|
-
|
25
|
-
## instance variables are hidden
|
26
|
-
w = Worker.new
|
27
|
-
w.metametaclass.instance_variable_set '@mattress', 'S&F'
|
28
|
-
w.instance_variables
|
29
|
-
## []
|
data/try/25_string_tryouts.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
|
3
|
-
## String can extend Attic
|
4
|
-
String.extend Attic
|
5
|
-
String.respond_to? :attic
|
6
|
-
#=> true
|
7
|
-
|
8
|
-
## save an instance variable the long way
|
9
|
-
s = ""
|
10
|
-
s.metametaclass.instance_variable_set '@mattress', 'S&F'
|
11
|
-
s.metametaclass.instance_variable_get '@mattress'
|
12
|
-
#=> 'S&F'
|
13
|
-
|
14
|
-
## can create attributes
|
15
|
-
String.attic :goodies
|
16
|
-
#=> [:goodies]
|
17
|
-
|
18
|
-
## save an instance variable the short way
|
19
|
-
s = ""
|
20
|
-
s.goodies = :california_king
|
21
|
-
p s.instance_variables
|
22
|
-
p s.attic_vars
|
23
|
-
s.goodies
|
24
|
-
#=> :california_king
|
25
|
-
|
26
|
-
## String instances don't cross streams
|
27
|
-
String.extend Attic
|
28
|
-
String.attic :name
|
29
|
-
a = "any"
|
30
|
-
a.name = :roger
|
31
|
-
a.name == "".name
|
32
|
-
#=> false
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
|
3
|
-
## has list of no metaclass classes
|
4
|
-
Object::NOMETACLASS
|
5
|
-
#=> [Symbol, Fixnum]
|
6
|
-
|
7
|
-
## Symbol metaclass raises exception
|
8
|
-
begin
|
9
|
-
:any.metaclass
|
10
|
-
rescue NoMetaClass
|
11
|
-
:success
|
12
|
-
end
|
13
|
-
#=> :success
|
14
|
-
|
15
|
-
## Symbol instances don't cross streams
|
16
|
-
Symbol.extend Attic
|
17
|
-
Symbol.attic :name
|
18
|
-
a, b = :symbol1, :symbol2
|
19
|
-
a.name = :roger
|
20
|
-
[a.name, b.name]
|
21
|
-
#=> [:roger, nil]
|
22
|
-
|
23
|
-
## metaclass? method exists
|
24
|
-
Symbol.extend Attic
|
25
|
-
:any.respond_to? :metaclass?
|
26
|
-
#=> true
|
27
|
-
|
28
|
-
## metaclass? method is false for a Symbol", false do
|
29
|
-
:any.metaclass?
|
30
|
-
#=> false
|
31
|
-
|
32
|
-
## A Symbol's attic vars appear in all_instance_variables" do
|
33
|
-
Symbol.extend Attic
|
34
|
-
Symbol.attic :name
|
35
|
-
a, b = :symbol1, :symbol2
|
36
|
-
a.name = :roger
|
37
|
-
a.all_instance_variables
|
38
|
-
#=> [:@___attic_name]
|
39
|
-
|
40
|
-
|
41
|
-
## A Symbol's attic vars do not appear in instance_variables" do
|
42
|
-
Symbol.extend Attic
|
43
|
-
Symbol.attic :name
|
44
|
-
a, b = :symbol1, :symbol2
|
45
|
-
a.name = :roger
|
46
|
-
a.instance_variables
|
47
|
-
#=> []
|
48
|
-
|
49
|
-
## knows attic variables", [:name] do
|
50
|
-
Symbol.attic_variables
|
51
|
-
#=> [:name]
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'attic'
|
2
|
-
|
3
|
-
class ::Worker
|
4
|
-
extend Attic
|
5
|
-
end
|
6
|
-
|
7
|
-
## can set value", 100 do
|
8
|
-
a = Worker.new
|
9
|
-
a.attic_variable_set :space, 100
|
10
|
-
a.attic_variable_get :space
|
11
|
-
#=> 100
|
12
|
-
|
13
|
-
## doesn't create accessor methods", false do
|
14
|
-
a = Worker.new
|
15
|
-
a.attic_variable_set :space, 100
|
16
|
-
a.respond_to? :space
|
17
|
-
#=> false
|
data/try/X1_metaclasses.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
# $ ruby tryouts/metaclasses.rb
|
2
|
-
|
3
|
-
class Object
|
4
|
-
|
5
|
-
# A convenient method for getting the metaclass of the current object.
|
6
|
-
# i.e.
|
7
|
-
#
|
8
|
-
# class << self; self; end;
|
9
|
-
#
|
10
|
-
def metaclass; class << self; self; end; end
|
11
|
-
|
12
|
-
# Execute a block +&blk+ within the metaclass of the current object.
|
13
|
-
def meta_eval &blk; metaclass.instance_eval &blk; end
|
14
|
-
|
15
|
-
# Add an instance method called +name+ to metaclass for the current object.
|
16
|
-
# This is useful because it will be available as a singleton method
|
17
|
-
# to all subclasses too.
|
18
|
-
def meta_def name, &blk
|
19
|
-
meta_eval { define_method name, &blk }
|
20
|
-
end
|
21
|
-
|
22
|
-
# Add a class method called +name+ for the current object's class. This
|
23
|
-
# isn't so special but it maintains consistency with meta_def.
|
24
|
-
def class_def name, &blk
|
25
|
-
class_eval { define_method name, &blk }
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
# A convenient method for getting the metaclass of the metaclass
|
30
|
-
# i.e.
|
31
|
-
#
|
32
|
-
# self.metaclass.metaclass
|
33
|
-
#
|
34
|
-
def metametaclass; self.metaclass.metaclass; end
|
35
|
-
|
36
|
-
def metameta_eval &blk; metametaclass.instance_eval &blk; end
|
37
|
-
|
38
|
-
def metameta_def name, &blk
|
39
|
-
metameta_eval { define_method name, &blk }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
# Create an instance method
|
45
|
-
class NamedArray1
|
46
|
-
class_eval do
|
47
|
-
define_method(:name) do
|
48
|
-
:roger
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
p [1, NamedArray1.new.name]
|
53
|
-
|
54
|
-
# Create getter and setter instance methods
|
55
|
-
class NamedArray2
|
56
|
-
class_eval do
|
57
|
-
define_method(:name) do
|
58
|
-
instance_variable_get("@name")
|
59
|
-
end
|
60
|
-
define_method(:name=) do |val|
|
61
|
-
instance_variable_set("@name", val)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
a = NamedArray2.new
|
66
|
-
a.name = :roger
|
67
|
-
p [2, a.name, a.instance_variables]
|
68
|
-
|
69
|
-
# Create getter and setter instance methods,
|
70
|
-
# store instance variable in metaclass
|
71
|
-
class NamedArray3
|
72
|
-
class_eval do
|
73
|
-
define_method(:name) do
|
74
|
-
metaclass.instance_variable_get("@name")
|
75
|
-
end
|
76
|
-
define_method(:name=) do |val|
|
77
|
-
metaclass.instance_variable_set("@name", val)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
a = NamedArray3.new
|
82
|
-
a.name = :roger
|
83
|
-
p [3, a.name, a.instance_variables, a.metaclass.instance_variables]
|
84
|
-
|
85
|
-
# Create a module with the which puts the functionality
|
86
|
-
# in NamedArray3 into a class method.
|
87
|
-
module StorageArea
|
88
|
-
def store *junk
|
89
|
-
junk.each do |name|
|
90
|
-
class_eval do
|
91
|
-
define_method(name) do
|
92
|
-
metaclass.instance_variable_get("@#{name}")
|
93
|
-
end
|
94
|
-
define_method("#{name}=") do |val|
|
95
|
-
metaclass.instance_variable_set("@#{name}", val)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
class NamedArray4
|
102
|
-
extend StorageArea
|
103
|
-
store :name
|
104
|
-
end
|
105
|
-
a = NamedArray4.new
|
106
|
-
a.name = :roger
|
107
|
-
p [4, a.name, a.instance_variables, a.metaclass.instance_variables]
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
data/try/X2_extending.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
$:.unshift './lib'
|
2
|
-
require 'attic'
|
3
|
-
|
4
|
-
class A
|
5
|
-
extend Attic
|
6
|
-
attic :andy
|
7
|
-
end
|
8
|
-
|
9
|
-
class B < A
|
10
|
-
attic :size
|
11
|
-
end
|
12
|
-
|
13
|
-
class C
|
14
|
-
extend Attic
|
15
|
-
attic :third
|
16
|
-
end
|
17
|
-
|
18
|
-
a, b, c = A.new, B.new, C.new
|
19
|
-
|
20
|
-
a.andy, b.andy = 1, 2
|
21
|
-
|
22
|
-
p [a.respond_to?(:andy), b.respond_to?(:andy)] # true, true
|
23
|
-
p [a.andy, b.andy] # 1, 2
|
24
|
-
|
25
|
-
p [a.class.attic_vars, b.class.attic_vars, c.class.attic_vars]
|
26
|
-
|
27
|
-
|