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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 611867f69c2201285532f3d052d239bc821f303d604e21a109c0256ce3fb0c47
4
- data.tar.gz: 8ca90d2184a63a227e320f17f3b6b811ecac01b7828311d3cb337ac7401dd7dc
3
+ metadata.gz: 46acf7bee0e43d24b1cd6c98a3875573b0125b00b5f171c12b52947c8099d908
4
+ data.tar.gz: 0ae6e9f1af73a7a30343e2030a4e28266501ed129d0a035a4cc6c74a18115c89
5
5
  SHA512:
6
- metadata.gz: 0bfdf2f3a6e0b9c7a538e62f468ac9b614c64e8394d021c1f7f41ffe8499f6ef6888c60a73bddee9a8331edd0436bdfc4f59c4866b1696469d2e9081baa44bf1
7
- data.tar.gz: c54ccecf2587ae16d6c15ea0d8ddb5e839e5e4eb1bee97ca087f01c7b16f5c903bdfb4fad84294fcd55b8682b6bcca1bfe07e27ab6832f3afd52d1c6b70a9c83
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.3.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
@@ -1,3 +1,5 @@
1
+ require "with_refinements"
2
+
1
3
  module Helloable
2
4
  refine(Object) do
3
5
  def hello
@@ -14,7 +16,6 @@ module Hiable
14
16
  end
15
17
  end
16
18
 
17
-
18
19
  class Person
19
20
  using WithRefinements
20
21
 
@@ -1,3 +1,3 @@
1
1
  module WithRefinements
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.eval('self'))
38
- bb.local_variables.each {|n| b.local_variable_set(n, bb.local_variable_get(n)) }
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
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.16"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "test-unit"
28
+ spec.add_development_dependency "benchmark_driver"
28
29
  end
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.3.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-01 00:00:00.000000000 Z
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