refr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/refr.rb +44 -0
- metadata +54 -0
data/lib/refr.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
6
|
+
#
|
7
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
8
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
9
|
+
#
|
10
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
11
|
+
#++
|
12
|
+
|
13
|
+
class Reference < BasicObject
|
14
|
+
Environment = ::Class.new(::BasicObject) {
|
15
|
+
def method_missing (id, *args, &block)
|
16
|
+
id
|
17
|
+
end
|
18
|
+
}.new
|
19
|
+
|
20
|
+
def initialize (name, vars)
|
21
|
+
@getter = ::Kernel::eval("lambda { #{name} }", vars)
|
22
|
+
@setter = ::Kernel::eval("lambda { |v| #{name} = v }", vars)
|
23
|
+
end
|
24
|
+
|
25
|
+
def __get__
|
26
|
+
@getter.call
|
27
|
+
end; alias ~ __get__
|
28
|
+
|
29
|
+
def __set__ (val)
|
30
|
+
@setter.call(val)
|
31
|
+
end; alias =~ __set__
|
32
|
+
|
33
|
+
def method_missing (id, *args, &block)
|
34
|
+
if __get__.respond_to? id
|
35
|
+
__get__.__send__(id, *args, &block)
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def ref (&block)
|
43
|
+
Reference.new(Reference::Environment.instance_eval(&block), block.binding)
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- meh.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-16 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: meh@paranoici.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/refr.rb
|
26
|
+
homepage: http://github.com/meh/refr
|
27
|
+
licenses: []
|
28
|
+
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.5
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Simple reference implementation
|
53
|
+
test_files: []
|
54
|
+
|