is_a 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +51 -0
- data/ext/is_a/extconf.rb +3 -0
- data/ext/is_a/is_a.c +26 -0
- data/is_a.gemspec +22 -0
- data/lib/is_a.rb +8 -0
- data/lib/is_a/version.rb +3 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Vasily Fedoseyev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# IsA
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'is_a'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install is_a
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/extensiontask'
|
5
|
+
Rake::ExtensionTask.new('is_a')
|
6
|
+
|
7
|
+
desc "Simple dump test,just to check if extension compiles and does not segfault on simple dump"
|
8
|
+
task :test => :compile do
|
9
|
+
require "bundler/setup"
|
10
|
+
require 'is_a'
|
11
|
+
|
12
|
+
class SomeDSL < BasicObject
|
13
|
+
def initialize
|
14
|
+
@search_me = 12345
|
15
|
+
end
|
16
|
+
def lala
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
obj = SomeDSL.new
|
21
|
+
|
22
|
+
def cls obj
|
23
|
+
cls = IsA.class_of(obj)
|
24
|
+
cls1 = cls
|
25
|
+
classes = []
|
26
|
+
while cls = cls.superclass
|
27
|
+
classes << cls
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Cls is #{cls1.inspect}, #{classes.inspect}"
|
31
|
+
cls1
|
32
|
+
end
|
33
|
+
|
34
|
+
c = cls obj
|
35
|
+
cls c
|
36
|
+
cls nil
|
37
|
+
|
38
|
+
id = IsA.id_of(obj)
|
39
|
+
puts "Id is #{id}"
|
40
|
+
if ObjectSpace._id2ref(id) == obj
|
41
|
+
puts "Getref ok"
|
42
|
+
else
|
43
|
+
puts "Getref FAIL"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
require 'heap_dump'
|
48
|
+
HeapDump.dump
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :test
|
data/ext/is_a/extconf.rb
ADDED
data/ext/is_a/is_a.c
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
|
5
|
+
static VALUE rb_mIsA;
|
6
|
+
|
7
|
+
|
8
|
+
static VALUE
|
9
|
+
rb_get_class_of(VALUE self, VALUE obj)
|
10
|
+
{
|
11
|
+
VALUE cls = rb_class_of(obj);
|
12
|
+
//printf("Class of %lu is %lu\n", obj / 2, cls / 2);
|
13
|
+
return cls;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
rb_object_id_of(VALUE self, VALUE obj)
|
18
|
+
{
|
19
|
+
return rb_obj_id(obj);
|
20
|
+
}
|
21
|
+
|
22
|
+
void Init_is_a(){
|
23
|
+
rb_mIsA = rb_define_module("IsA");
|
24
|
+
rb_define_singleton_method(rb_mIsA, "class_of", rb_get_class_of, 1);
|
25
|
+
rb_define_singleton_method(rb_mIsA, "id_of", rb_object_id_of, 1);
|
26
|
+
}
|
data/is_a.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/is_a/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Vasily Fedoseyev"]
|
6
|
+
gem.email = ["vasilyfedoseyev@gmail.com"]
|
7
|
+
gem.description = %q{Fear weak references to BasicObject no more}
|
8
|
+
gem.summary = %q{Defines methods to introspect any ruby object more deeply}
|
9
|
+
gem.homepage = "http://github.com/Vasfed/is_a"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "is_a"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = IsA::VERSION
|
17
|
+
|
18
|
+
gem.extensions = "ext/is_a/extconf.rb"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake-compiler"
|
21
|
+
gem.add_development_dependency "heap_dump"
|
22
|
+
end
|
data/lib/is_a.rb
ADDED
data/lib/is_a/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: is_a
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vasily Fedoseyev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-compiler
|
16
|
+
requirement: &70149844404480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70149844404480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: heap_dump
|
27
|
+
requirement: &70149844403740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70149844403740
|
36
|
+
description: Fear weak references to BasicObject no more
|
37
|
+
email:
|
38
|
+
- vasilyfedoseyev@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions:
|
41
|
+
- ext/is_a/extconf.rb
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- ext/is_a/extconf.rb
|
50
|
+
- ext/is_a/is_a.c
|
51
|
+
- is_a.gemspec
|
52
|
+
- lib/is_a.rb
|
53
|
+
- lib/is_a/version.rb
|
54
|
+
homepage: http://github.com/Vasfed/is_a
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.15
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Defines methods to introspect any ruby object more deeply
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|