with_refinements 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Gemfile.lock +3 -1
- data/examples/b.rb +31 -0
- data/examples/greeting.rb +2 -1
- data/lib/with_refinements/version.rb +1 -1
- data/lib/with_refinements.rb +15 -4
- data/with_refinements.gemspec +1 -0
- data.tar.gz.sig +0 -0
- metadata +17 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46acf7bee0e43d24b1cd6c98a3875573b0125b00b5f171c12b52947c8099d908
|
4
|
+
data.tar.gz: 0ae6e9f1af73a7a30343e2030a4e28266501ed129d0a035a4cc6c74a18115c89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b184d7693abd0d8efb1bf5aecc7ca4f8369eceaa7a7d92a4c6139156aaf7ccc5c7d128783c27cec1dbf5b8efacdf35489685968b6c4c04e17401edae586f335
|
7
|
+
data.tar.gz: 64b53f1b80c3d79467d38ad1ad312efec6aa0f7196f1c9d73de9aeb7833f2531644c1385262013a32981a013c4b36b687e17a2ec6310555866062f6811982c15
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
with_refinements (0.
|
4
|
+
with_refinements (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
benchmark_driver (0.14.6)
|
9
10
|
power_assert (1.1.3)
|
10
11
|
rake (10.5.0)
|
11
12
|
test-unit (3.2.8)
|
@@ -15,6 +16,7 @@ PLATFORMS
|
|
15
16
|
ruby
|
16
17
|
|
17
18
|
DEPENDENCIES
|
19
|
+
benchmark_driver
|
18
20
|
bundler (~> 1.16)
|
19
21
|
rake (~> 10.0)
|
20
22
|
test-unit
|
data/examples/b.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "benchmark_driver"
|
2
|
+
|
3
|
+
Benchmark.driver do |x|
|
4
|
+
x.prelude <<~RUBY
|
5
|
+
require "bundler/setup"
|
6
|
+
require "with_refinements"
|
7
|
+
|
8
|
+
using WithRefinements
|
9
|
+
|
10
|
+
module M
|
11
|
+
refine(String) do
|
12
|
+
def goodbye
|
13
|
+
-"goodbye"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
RUBY
|
18
|
+
|
19
|
+
x.report 'plain', %{
|
20
|
+
using M
|
21
|
+
"hello".goodbye
|
22
|
+
}
|
23
|
+
|
24
|
+
x.report 'with_refinements', %{
|
25
|
+
with_refinements(M) { "hello".goodbye }
|
26
|
+
}
|
27
|
+
|
28
|
+
x.report 'with_refinements(local_variables: false)', %{
|
29
|
+
with_refinements(M, local_variables: false) { "hello".goodbye }
|
30
|
+
}
|
31
|
+
end
|
data/examples/greeting.rb
CHANGED
data/lib/with_refinements.rb
CHANGED
@@ -26,7 +26,7 @@ module WithRefinements
|
|
26
26
|
end
|
27
27
|
|
28
28
|
refine(Object) do
|
29
|
-
def with_refinements(*ms, &block)
|
29
|
+
def with_refinements(*ms, local_variables: true, &block)
|
30
30
|
# enable refinements
|
31
31
|
b = WithRefinements.clean_binding
|
32
32
|
b.local_variable_set(:__modules__, ms)
|
@@ -34,11 +34,22 @@ module WithRefinements
|
|
34
34
|
|
35
35
|
# setup block eval context
|
36
36
|
bb = block.binding
|
37
|
-
b.local_variable_set(:__self__, bb.
|
38
|
-
|
37
|
+
b.local_variable_set(:__self__, bb.receiver)
|
38
|
+
|
39
|
+
# copy local_variables
|
40
|
+
if local_variables
|
41
|
+
bb.local_variables.each {|n| b.local_variable_set(n, bb.local_variable_get(n)) }
|
42
|
+
end
|
39
43
|
|
40
44
|
# eval block code
|
41
|
-
b.eval("__self__.instance_eval #{WithRefinements.code_from_block(block)}")
|
45
|
+
ret = b.eval("__self__.instance_eval #{WithRefinements.code_from_block(block)}")
|
46
|
+
|
47
|
+
# write back local_variables
|
48
|
+
if local_variables
|
49
|
+
bb.local_variables.each {|n| bb.local_variable_set(n, b.local_variable_get(n)) }
|
50
|
+
end
|
51
|
+
|
52
|
+
ret
|
42
53
|
end
|
43
54
|
end
|
44
55
|
end
|
data/with_refinements.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: with_refinements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiei Miyagi
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
OKwDKKYe2ogJ/XrOjTltlugSNvq/NgD53wc4TA0F5KofdIZSJELTCUyyZMPztwI4
|
35
35
|
OawPtyIyOegL6pM8fc7IfzLzjkdO3Bis1qFZcg==
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2018-08-
|
37
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: bundler
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: benchmark_driver
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
81
95
|
description:
|
82
96
|
email:
|
83
97
|
- hanachin@gmail.com
|
@@ -94,6 +108,7 @@ files:
|
|
94
108
|
- Rakefile
|
95
109
|
- bin/console
|
96
110
|
- bin/setup
|
111
|
+
- examples/b.rb
|
97
112
|
- examples/greeting.rb
|
98
113
|
- lib/with_refinements.rb
|
99
114
|
- lib/with_refinements/version.rb
|
metadata.gz.sig
CHANGED
Binary file
|