ghost_attributes 0.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.
- data/lib/ghost_attributes.rb +27 -0
- metadata +64 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# GhostAttributes is a silly example of how you can write a version of
|
2
|
+
# attr_accessor using closures instead of instance variables.
|
3
|
+
#
|
4
|
+
# Example usage:
|
5
|
+
# class Hippo
|
6
|
+
# include GhostAttributes
|
7
|
+
# ghost_accessor :name
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# hippo = Hippo.new
|
11
|
+
# hippo.name = "Humphrey"
|
12
|
+
# hippo.name # => "Humphrey"
|
13
|
+
|
14
|
+
module GhostAttributes
|
15
|
+
def self.included klass
|
16
|
+
def klass.ghost_accessor var
|
17
|
+
ghost_var = nil
|
18
|
+
define_method "#{var}" do
|
19
|
+
ghost_var
|
20
|
+
end
|
21
|
+
define_method "#{var}=" do |val|
|
22
|
+
ghost_var = val
|
23
|
+
end
|
24
|
+
nil # so that the call doesn't return a funny-looking proc
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghost_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alan O'Donnell
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-14 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A silly example of how to use closures to mimic attr_accessor.
|
22
|
+
email: alan.m.odonnell@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/ghost_attributes.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://rubygems.org/gems/ghost_attributes
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: A silly example of how to use closures to mimic attr_accessor.
|
63
|
+
test_files: []
|
64
|
+
|