ruby_patch 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  module RubyPatch
2
2
  class ::Class
3
+ def posterity_of?(klass)
4
+ self.ancestors.include?(klass)
5
+ end
6
+
3
7
  def children()
4
8
  posterities.select{|c|
5
9
  c.superclass == self
@@ -0,0 +1,7 @@
1
+ module Enumerable
2
+ def classify(&block)
3
+ h = Hash.new{[]}
4
+ self.each{|o| h[yield(o)] += [o]}
5
+ h
6
+ end
7
+ end
@@ -1,5 +1,8 @@
1
1
  module RubyPatch
2
2
  class ::Object
3
+ def exception?()
4
+ self.class.posterity_of?(Exception)
5
+ end
3
6
 
4
7
  # @return [Hash]
5
8
  def parse_caller(backtrace)
@@ -1,3 +1,3 @@
1
1
  module RubyPatch
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/ruby_patch.rb CHANGED
@@ -4,4 +4,5 @@ module RubyPatch
4
4
  require 'ruby_patch/class'
5
5
  require 'ruby_patch/string'
6
6
  require 'ruby_patch/time'
7
+ require 'ruby_patch/enumerable'
7
8
  end
data/ruby_patch.gemspec CHANGED
@@ -5,10 +5,10 @@ Gem::Specification.new do |s|
5
5
  s.name = 'ruby_patch'
6
6
  s.summary = "Monky patches for ruby."
7
7
  s.version = RubyPatch::VERSION
8
- s.add_development_dependency 'rspec', '~> 2'
9
- s.add_development_dependency 'simplecov', '~> 0'
8
+ s.add_development_dependency 'rspec', '~> 2.10'
9
+ s.add_development_dependency 'simplecov', '~> 0.6'
10
10
  s.author = 'kshramt'
11
11
  s.description = "Monkey patches used by kshramt's libraries."
12
- s.required_ruby_version = '>= 1.9.0'
12
+ s.required_ruby_version = '~> 1.9'
13
13
  s.test_files.concat `git ls-files spec`.split.select{|path| path =~ /_spec\.rb/}
14
14
  end
@@ -8,6 +8,17 @@ describe Class do
8
8
  class Dummy::Child < Dummy; end
9
9
  class Dummy::Child::GrandChild < Dummy::Child; end
10
10
  end
11
+
12
+ describe '#posterity_of?' do
13
+ it do
14
+ Integer.posterity_of?(Numeric).should be_true
15
+ end
16
+
17
+ it do
18
+ Symbol.posterity_of?(Numeric).should be_false
19
+ end
20
+ end
21
+
11
22
  describe '#posterities' do
12
23
  it do
13
24
  Dummy.posterities.sort.should == [Dummy::Child, Dummy::Child::GrandChild].sort
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'ruby_patch'
3
+
4
+ describe Enumerable do
5
+ describe 'classify' do
6
+ it do
7
+ (1..4).classify{|i| i.odd?}.should == {
8
+ true => [1, 3],
9
+ false => [2, 4],
10
+ }
11
+ end
12
+
13
+ it do
14
+ [1, '1', :'1'].classify{|v| v.class}.should == {
15
+ Fixnum => [1],
16
+ String => ['1'],
17
+ Symbol => [:'1'],
18
+ }
19
+ end
20
+ end
21
+ end
@@ -3,6 +3,21 @@ require 'spec_helper'
3
3
  require 'ruby_patch/object'
4
4
 
5
5
  describe Object do
6
+
7
+ describe '#exception?' do
8
+ context 'Posterity of Exception' do
9
+ it do
10
+ StandardError.new.should be_true
11
+ end
12
+ end
13
+
14
+ context 'Not a posterity of Exception' do
15
+ it do
16
+ 3.exception?.should be_false
17
+ end
18
+ end
19
+ end
20
+
6
21
  describe '#__DIR__' do
7
22
  it do
8
23
  __DIR__.should == File.dirname(__FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &74368400 !ruby/object:Gem::Requirement
16
+ requirement: &2154059860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '2'
21
+ version: '2.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *74368400
24
+ version_requirements: *2154059860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simplecov
27
- requirement: &74368150 !ruby/object:Gem::Requirement
27
+ requirement: &2154059240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '0.6'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *74368150
35
+ version_requirements: *2154059240
36
36
  description: Monkey patches used by kshramt's libraries.
37
37
  email:
38
38
  executables: []
@@ -41,6 +41,7 @@ extra_rdoc_files: []
41
41
  files:
42
42
  - lib/ruby_patch.rb
43
43
  - lib/ruby_patch/class.rb
44
+ - lib/ruby_patch/enumerable.rb
44
45
  - lib/ruby_patch/object.rb
45
46
  - lib/ruby_patch/string.rb
46
47
  - lib/ruby_patch/time.rb
@@ -48,6 +49,7 @@ files:
48
49
  - rakefile
49
50
  - ruby_patch.gemspec
50
51
  - spec/ruby_patch/class_spec.rb
52
+ - spec/ruby_patch/enumerable_spec.rb
51
53
  - spec/ruby_patch/object_spec.rb
52
54
  - spec/ruby_patch/string_spec.rb
53
55
  - spec/ruby_patch/time_spec.rb
@@ -62,9 +64,9 @@ require_paths:
62
64
  required_ruby_version: !ruby/object:Gem::Requirement
63
65
  none: false
64
66
  requirements:
65
- - - ! '>='
67
+ - - ~>
66
68
  - !ruby/object:Gem::Version
67
- version: 1.9.0
69
+ version: '1.9'
68
70
  required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  none: false
70
72
  requirements:
@@ -73,12 +75,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  version: '0'
74
76
  requirements: []
75
77
  rubyforge_project:
76
- rubygems_version: 1.8.11
78
+ rubygems_version: 1.8.15
77
79
  signing_key:
78
80
  specification_version: 3
79
81
  summary: Monky patches for ruby.
80
82
  test_files:
81
83
  - spec/ruby_patch/class_spec.rb
84
+ - spec/ruby_patch/enumerable_spec.rb
82
85
  - spec/ruby_patch/object_spec.rb
83
86
  - spec/ruby_patch/string_spec.rb
84
87
  - spec/ruby_patch/time_spec.rb