refinements_robbery 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de81c6a3ae14051c85442f373d81b1a9c472bea3f37a0abc3c2d07db6df1226f
4
+ data.tar.gz: 4b16b650bbffa0b4924d752f53704adf83845c782a16363ede7e3ee4fb0f8c8c
5
+ SHA512:
6
+ metadata.gz: 69ae8e49a3738d4962005181ffc56d368c96432d6ea50f1a8cc671ac72fbb5aed38bf5ad4f7ad2e7102d57a00255a489e56bb09bde02978988b268161ef95d39
7
+ data.tar.gz: a76fbc1ef7ea9642c0285d08946bfddc2487e701a33f45117028cc7af64121d2783ffdb99db0ddad4c0d49b2ff02cc28f289b5425b47028762512780f3196261
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in refinements_robbery.gemspec
6
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ refinements_robbery (0.1.0)
5
+ fiddle
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ fiddle (1.0.0)
12
+ rake (10.5.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.0)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.2)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.17)
32
+ rake (~> 10.0)
33
+ refinements_robbery!
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.17.1
@@ -0,0 +1,112 @@
1
+ # RefinementsRobbery
2
+
3
+ Robbing the buried Refinements from ObjectSpace.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'refinements_robbery'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install refinements_robbery
20
+
21
+ ## Usage
22
+
23
+ Require it and rob the refinements.
24
+
25
+ ```rb
26
+ require "refinements_robbery"
27
+ using *RefinementsRobbery.rob(RefinedClassWhatever)
28
+ ```
29
+
30
+ ### Example
31
+
32
+ ```rb
33
+ class TreasureIsland
34
+ using Module.new {
35
+ refine(TreasureIsland) {
36
+ def safe
37
+ @safe ||= []
38
+ end
39
+ }
40
+ }
41
+
42
+ def initialize(treasures)
43
+ treasures.each { |t| safe << t }
44
+ freeze
45
+ end
46
+
47
+ def treasure_island?
48
+ !safe.empty?
49
+ end
50
+ freeze
51
+ end
52
+
53
+ island = TreasureIsland.new(["💰", "🏆", "💎"])
54
+
55
+ if island.treasure_island?
56
+ puts "there are treasures!"
57
+ else
58
+ puts "where are the treasures?"
59
+ end
60
+
61
+ # bag = []
62
+ # while t = island.safe.shift # undefined method `safe' for #<TreasureIsland:0x00005557b282a1b8> (NoMethodError)
63
+ # bag << t
64
+ # end
65
+
66
+ # class TreasureIsland
67
+ # def safe # can't modify frozen class (FrozenError)
68
+ # @safe
69
+ # end
70
+ # end
71
+
72
+ # def island.safe # can't modify frozen object (FrozenError)
73
+ # @safe
74
+ # end
75
+
76
+ require "refinements_robbery"
77
+
78
+ using *RefinementsRobbery.rob(TreasureIsland)
79
+
80
+ bag = []
81
+ while t = island.safe.shift
82
+ bag << t
83
+ end
84
+
85
+ if island.treasure_island?
86
+ puts "there are treasures!"
87
+ else
88
+ puts "where are the treasures?"
89
+ end
90
+
91
+ puts "treasures are in my bag: #{bag}"
92
+ ```
93
+
94
+ Result:
95
+
96
+ ```
97
+ % bundle exec ruby foo.rb
98
+ there are treasures!
99
+ where are the treasures?
100
+ treasures are in my bag: ["💰", "🏆", "💎"]
101
+ ```
102
+
103
+
104
+ ## Development
105
+
106
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
107
+
108
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
109
+
110
+ ## Contributing
111
+
112
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hanachin/refinements_robbery.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "refinements_robbery"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ require "refinements_robbery/version"
2
+ require "fiddle"
3
+
4
+ module RefinementsRobbery
5
+ class Error < StandardError; end
6
+
7
+ class << self
8
+ def rob(klass)
9
+ ObjectSpace.each_object(Module).select {|m|
10
+ rb_refinement_module_get_refined_class(m) == klass
11
+ }.map {|m|
12
+ defined_at(m)
13
+ }.uniq
14
+ end
15
+
16
+ private
17
+
18
+ def rb_intern_str(str)
19
+ rb_intern_str = Fiddle::Handle::DEFAULT["rb_intern_str"]
20
+ rb_intern_str_f = Fiddle::Function.new(rb_intern_str, [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP)
21
+ rb_intern_str_f.call(Fiddle.dlwrap(str))
22
+ end
23
+
24
+ def rb_attr_get(mod, str)
25
+ id = rb_intern_str(str)
26
+ rb_attr_get = Fiddle::Handle::DEFAULT["rb_attr_get"]
27
+ rb_attr_get_f = Fiddle::Function.new(rb_attr_get, [Fiddle::TYPE_VOIDP] * 2, Fiddle::TYPE_VOIDP)
28
+ m = Fiddle.dlwrap(mod)
29
+ Fiddle.dlunwrap(rb_attr_get_f.call(m, id))
30
+ end
31
+
32
+ def defined_at(mod)
33
+ rb_attr_get(mod, "__defined_at__")
34
+ end
35
+
36
+ def rb_refinement_module_get_refined_class(mod)
37
+ rb_attr_get(mod, "__refined_class__")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module RefinementsRobbery
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "refinements_robbery/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "refinements_robbery"
7
+ spec.version = RefinementsRobbery::VERSION
8
+ spec.authors = ["Seiei Miyagi"]
9
+ spec.email = ["hanachin@gmail.com"]
10
+
11
+ spec.summary = %q{Robbing the buried Refinements from ObjectSpace}
12
+ spec.homepage = "https://github.com/hanachin/refinements_robbery"
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "fiddle"
24
+ spec.add_development_dependency "bundler", "~> 1.17"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinements_robbery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Seiei Miyagi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fiddle
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - hanachin@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/refinements_robbery.rb
86
+ - lib/refinements_robbery/version.rb
87
+ - refinements_robbery.gemspec
88
+ homepage: https://github.com/hanachin/refinements_robbery
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.7.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Robbing the buried Refinements from ObjectSpace
111
+ test_files: []