refr 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/refr.rb +51 -47
  2. metadata +52 -28
data/lib/refr.rb CHANGED
@@ -2,63 +2,67 @@
2
2
  # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
3
  # Version 2, December 2004
4
4
  #
5
- # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
6
- #
7
5
  # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
8
6
  # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9
7
  #
10
8
  # 0. You just DO WHAT THE FUCK YOU WANT TO.
11
9
  #++
12
10
 
13
- class Reference
14
- class << self
15
- def normalize (value)
16
- if (value.___is_a_reference___ rescue false)
17
- value.__get_referenced__
18
- else
19
- value
20
- end
21
- end; alias - normalize
11
+ require 'blankslate'
12
+
13
+ class Reference < BlankSlate
14
+ class << self
15
+ def normalize (value)
16
+ if (value.___is_a_reference___ rescue false)
17
+ value.___get_referenced___
18
+ else
19
+ value
20
+ end
21
+ end; alias - normalize
22
+
23
+ def local (&block)
24
+ self.new(block.call, block.binding)
25
+ end
22
26
 
23
- def local (&block)
24
- self.new(block.call, block.binding)
25
- end
27
+ def [] (value, force=false)
28
+ if (value.___is_a_reference___ rescue false) && !force
29
+ value
30
+ else
31
+ self.local { :value }
32
+ end
33
+ end
34
+ end
26
35
 
27
- def [] (value, force=false)
28
- if (value.___is_a_reference___ rescue false) && !force
29
- value
30
- else
31
- self.local { :value }
32
- end
33
- end
34
- end
36
+ def initialize (name, binding)
37
+ begin
38
+ @getter = Kernel::eval("lambda { #{name} }", binding)
39
+ @setter = Kernel::eval("lambda { |v| #{name} = v }", binding)
40
+ rescue Exception => e
41
+ Kernel::raise NameError, "#{name} isn't a valid variable name"
42
+ end
43
+ end
35
44
 
36
- tmp, $VERBOSE = $VERBOSE, nil
37
- Object.instance_methods.each {|meth|
38
- undef_method meth
39
- }
40
- $VERBOSE = tmp
45
+ def ___get_referenced___
46
+ @getter.call
47
+ end; alias ~ ___get_referenced___
41
48
 
42
- def initialize (name, vars)
43
- begin
44
- @getter = ::Kernel::eval("lambda { #{name} }", vars)
45
- @setter = ::Kernel::eval("lambda { |v| #{name} = v }", vars)
46
- rescue ::Exception => e
47
- ::Kernel::raise ::NameError, "#{name} isn't a valid variable name"
48
- end
49
- end
50
-
51
- def __get_referenced__
52
- @getter.call
53
- end; alias ~ __get_referenced__
54
-
55
- def __set_referenced__ (val)
56
- @setter.call(val)
57
- end; alias =~ __set_referenced__
49
+ def ___set_referenced___ (val)
50
+ @setter.call(val)
51
+ end; alias =~ ___set_referenced___
58
52
 
59
- def method_missing (id, *args, &block)
60
- __get_referenced__.__send__(id, *args, &block)
61
- end
53
+ def method_missing (id, *args, &block)
54
+ ___get_referenced___.__send__(id, *args, &block)
55
+ end
56
+
57
+ def ___is_a_reference___; true; end
58
+ end
62
59
 
63
- def ___is_a_reference___; true; end
60
+ module Kernel
61
+ def Reference (*args, &block)
62
+ if args.empty? && block
63
+ Reference.local(&block)
64
+ else
65
+ Reference[*args]
66
+ end
67
+ end
64
68
  end
metadata CHANGED
@@ -1,54 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: refr
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
4
5
  prerelease:
5
- version: 0.0.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - meh.
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-27 00:00:00 Z
14
- dependencies: []
15
-
12
+ date: 2011-12-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: blankslate
16
+ requirement: &7410360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *7410360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &7408940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *7408940
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &7408360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *7408360
16
47
  description:
17
48
  email: meh@paranoici.org
18
49
  executables: []
19
-
20
50
  extensions: []
21
-
22
51
  extra_rdoc_files: []
23
-
24
- files:
52
+ files:
25
53
  - lib/refr.rb
26
54
  homepage: http://github.com/meh/refr
27
55
  licenses: []
28
-
29
56
  post_install_message:
30
57
  rdoc_options: []
31
-
32
- require_paths:
58
+ require_paths:
33
59
  - lib
34
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
35
61
  none: false
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: "0"
40
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
67
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
46
72
  requirements: []
47
-
48
73
  rubyforge_project:
49
- rubygems_version: 1.8.5
74
+ rubygems_version: 1.8.10
50
75
  signing_key:
51
76
  specification_version: 3
52
77
  summary: Simple reference implementation
53
78
  test_files: []
54
-