proc_tweaker 0.0.2
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/lib/proc_tweaker.rb +44 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b5bb713135a56d82d7a4d80c4e496c53a36e7448a3a6f57636c76414d4e4e3f
|
4
|
+
data.tar.gz: 28ffb330a45101010af5d728d72900d494a70d74025319c7c51557552d464dc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5426b0a1fc3ee4ed4e47db23b35ec1b1f08e6ba0289558affcbaba1517f70f95294d5c32904b0fdd683bad62dd01a6c76f05b775b0085f2a76cd35e920b6be2
|
7
|
+
data.tar.gz: 8164eef6f4ea62219d7ec13243b1b60df2280d899bd73830ce11c0e22ac261e251c30f8c3689f8e1015436dfce347d2df9779bb04e4207c1c3c88990c7474ac7
|
data/lib/proc_tweaker.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
class LookupStack
|
2
|
+
def initialize(bindings = [])
|
3
|
+
@bindings = bindings
|
4
|
+
end
|
5
|
+
|
6
|
+
def method_missing(m, *args)
|
7
|
+
@bindings.reverse_each do |bind|
|
8
|
+
begin
|
9
|
+
method = eval('method(%s)' % m.inspect, bind)
|
10
|
+
rescue NameError
|
11
|
+
else
|
12
|
+
return method.call(*args)
|
13
|
+
end
|
14
|
+
begin
|
15
|
+
value = eval(m.to_s, bind)
|
16
|
+
return value
|
17
|
+
rescue NameError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
raise NoMethodError
|
21
|
+
end
|
22
|
+
|
23
|
+
def push_binding(bind)
|
24
|
+
@bindings.push bind
|
25
|
+
end
|
26
|
+
|
27
|
+
def push_instance(obj)
|
28
|
+
@bindings.push obj.instance_eval { binding }
|
29
|
+
end
|
30
|
+
|
31
|
+
def push_hash(vars)
|
32
|
+
push_instance Struct.new(*vars.keys).new(*vars.values)
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_proc(p, *args)
|
36
|
+
instance_exec(*args, &p)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Proc
|
41
|
+
def call_with_binding(bind, *args)
|
42
|
+
LookupStack.new([bind]).run_proc(self, *args)
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: proc_tweaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elliot Bertin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
A simple Proc Tweaker gem to change the way procs work. This code is not mine and I do not claim it to be. I just wanted to make it into a gem.
|
15
|
+
I found it years ago on the internet and I have no idea who the original author is. It's useful though, so I thought I'd share it.
|
16
|
+
email: bertinelliot@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/proc_tweaker.rb
|
22
|
+
homepage: https://rubygems.org/gems/proc_tweaker
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.4.6
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Proc Tweaker enabler!
|
45
|
+
test_files: []
|