is_a 0.0.2 → 0.0.3

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.
Files changed (4) hide show
  1. data/README.md +21 -2
  2. data/lib/is_a.rb +12 -0
  3. data/lib/is_a/version.rb +1 -1
  4. metadata +3 -3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # IsA
2
2
 
3
- TODO: Write a gem description
3
+ A small library of missing ruby methods for introspection. See Usage.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,26 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ require 'is_a'
23
+
24
+ obj = BasicObject.new
25
+ begin
26
+ obj.class
27
+ rescue
28
+ puts "Yep, BasicObject will not tell you it's class"
29
+ cls = IsA.class_of(obj)
30
+ puts "But IsA will. It's #{cls}"
31
+ end
32
+
33
+ IsA.object?(obj) # => false
34
+ IsA.object?("anything that is derived from Object") # => true
35
+
36
+ #Also on 1.9.2 there's no way of getting object_id of BasicObject, here it is:
37
+ id = IsA.id_of(obj) # or alias ObjectSpace._ref2id(obj)
38
+ ObjectSpace._id2ref(id) == obj # => true
39
+ #For 1.9.3 use BasicObject#__id__
40
+ ```
22
41
 
23
42
  ## Contributing
24
43
 
@@ -13,4 +13,16 @@ module IsA
13
13
  return false
14
14
  end
15
15
  end
16
+
17
+ def self._ref2id obj
18
+ self.id_of(obj)
19
+ end
16
20
  end
21
+
22
+ unless ObjectSpace.respond_to? :_ref2id
23
+ module ObjectSpace
24
+ def self._ref2id(obj)
25
+ IsA._ref2id(obj)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module IsA
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_a
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
16
- requirement: &70170107218200 !ruby/object:Gem::Requirement
16
+ requirement: &70116595563300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70170107218200
24
+ version_requirements: *70116595563300
25
25
  description: Fear weak references to BasicObject no more
26
26
  email:
27
27
  - vasilyfedoseyev@gmail.com