contextual_proc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/contextual_proc.rb +22 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8eaf7b6ae585511c5721330c0f27dd46738b95b
4
+ data.tar.gz: 28eadc8fc9e02f2dc3a3a2cec929c97b340f8e5f
5
+ SHA512:
6
+ metadata.gz: 5a65f58fa01b78bc7144ae252f45aebfb6f33d25e29dca987cd89b22b9957a56e5756d5011f3e421d6a04152c2f5aee508b9655e478fbb3c3c603e74b4c79ee7
7
+ data.tar.gz: 64caf19312d5c61ab8b69abf92d18017a928f49fda9d0b96f5b24aeecaa71053f452f0620bba3a90e5800140e1b14d66020cf3ac9693842948d67d045c00696c
@@ -0,0 +1,22 @@
1
+ class ContextualProc < Proc
2
+ def apply(bind, *args)
3
+ @binding = bind
4
+ instance_exec(*args, &self)
5
+ end
6
+
7
+ def method_missing(m, *args)
8
+ begin
9
+ method = eval("method(%s)" % m.inspect, @binding)
10
+ rescue NameError
11
+ else
12
+ return method.call(*args)
13
+ end
14
+ begin
15
+ value = eval(m.to_s, @binding)
16
+ return value
17
+ rescue NameError
18
+ end
19
+
20
+ super
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contextual_proc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Baumstark
8
+ - Jan Renra Gloser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-07-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A proc extension that is able to execute in another context/binding a
15
+ little bit inspired by JavaScript. Original implementation can be found [here](https://github.com/niklasb/ruby-dynamic-binding)
16
+ email: jan.renra.gloser@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/contextual_proc.rb
22
+ homepage: https://github.com/renra/ruby-dynamic-binding
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.5.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Procs that can run in an arbitrary context
45
+ test_files: []
46
+ has_rdoc: