tbpgr_utils 0.0.129 → 0.0.130
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.
- checksums.yaml +4 -4
- data/README.md +34 -0
- data/lib/open_classes/object/grep_method.rb +44 -0
- data/lib/open_classes/object.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/object/grep_method_spec.rb +88 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eb04c565481f5ab296a1c437ca8a6726cf0d323
|
4
|
+
data.tar.gz: e830aa0554fbbfff121de0c298308d5abe06bb5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3b83a7a389fb208c032f7e142d39fe99398410b378777efe39cbdcd4e1b047de1cc47681d3f3c28b0bf749fe8eeac054aafa4103e04f3a0cf6ecac4547ed9f
|
7
|
+
data.tar.gz: bd5f37724aa036a7e1f8ae46a86c234b86b6f84fc5c627ef26673ae3e7b71f26529b6edbf72c2904b4977b95bce7d37f955c361f9922b7209184fa336747022f
|
data/README.md
CHANGED
@@ -131,6 +131,7 @@ Or install it yourself as:
|
|
131
131
|
|[TbpgrUtils Numeric to_oct_table](#numeric-to_oct_table) |oct table |
|
132
132
|
|[TbpgrUtils Object#any_of?](#objectany_of) |if self match any one of items, return true |
|
133
133
|
|[TbpgrUtils Object#boolean?](#objectboolean) |data type check for boolean |
|
134
|
+
|[TbpgrUtils Object#grep_method](#objectgrep_method) |grep class method |
|
134
135
|
|[TbpgrUtils Object#grep_public_instance_method](#objectgrep_public_instance_method) |grep public instance method |
|
135
136
|
|[TbpgrUtils Object#guard](#objectguard) |data type check for guard |
|
136
137
|
|[TbpgrUtils Object#method_nameable?](#objectmethod_nameable) |object can use method name or not |
|
@@ -2938,6 +2939,38 @@ hoge false # => "not guard"
|
|
2938
2939
|
|
2939
2940
|
[back to list](#list)
|
2940
2941
|
|
2942
|
+
### Object#grep_method
|
2943
|
+
target class
|
2944
|
+
|
2945
|
+
~~~ruby
|
2946
|
+
require 'tbpbr_utils'
|
2947
|
+
|
2948
|
+
class GrepMethod
|
2949
|
+
def self.public_method1;end
|
2950
|
+
def self.public_method2;end
|
2951
|
+
def self.public_method11;end
|
2952
|
+
protected
|
2953
|
+
def self.protected_method1;end
|
2954
|
+
def self.protected_method2;end
|
2955
|
+
def self.protected_method11;end
|
2956
|
+
private
|
2957
|
+
def self.private_method1;end
|
2958
|
+
def self.private_method2;end
|
2959
|
+
def self.private_method11;end
|
2960
|
+
end
|
2961
|
+
|
2962
|
+
GrepMethod.new.grep_method :public_method1, false # => [:public_method1]
|
2963
|
+
GrepMethod.grep_method :public_method1, false # => [:public_method1]
|
2964
|
+
GrepMethod.new.grep_method /public_method1/, false # => [:public_method1, :public_method11]
|
2965
|
+
GrepMethod.grep_method /public_method1/, false # => [:public_method1, :public_method11]
|
2966
|
+
GrepMethod.new.grep_method /public_method3/, false # => []
|
2967
|
+
GrepMethod.grep_method /public_method3/, false # => []
|
2968
|
+
GrepMethod.new.grep_method :__send__, true # => [:__send__]
|
2969
|
+
GrepMethod.grep_method :__send__, true # => [:__send__]
|
2970
|
+
~~~
|
2971
|
+
|
2972
|
+
[back to list](#list)
|
2973
|
+
|
2941
2974
|
### Object#grep_public_instance_method
|
2942
2975
|
~~~ruby
|
2943
2976
|
require 'tbpbr_utils'
|
@@ -3678,6 +3711,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
3678
3711
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
3679
3712
|
|
3680
3713
|
## History
|
3714
|
+
* version 0.0.130 : add Object#grep_method
|
3681
3715
|
* version 0.0.129 : add Object#grep_public_instance_method
|
3682
3716
|
* version 0.0.128 : add Array#exchange, change Kernel#bulk_puts_eval output format(justify)
|
3683
3717
|
* version 0.0.127 : add String#uniq_size
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Object
|
4
|
+
class Object
|
5
|
+
def self.grep_method(search, all = true)
|
6
|
+
search = search.to_sym unless search.is_a? Regexp
|
7
|
+
methods(all).grep search
|
8
|
+
end
|
9
|
+
|
10
|
+
# grep public instance method
|
11
|
+
#
|
12
|
+
# === Example
|
13
|
+
#
|
14
|
+
# target class
|
15
|
+
#
|
16
|
+
# class GrepMethod
|
17
|
+
# def self.public_method1;end
|
18
|
+
# def self.public_method2;end
|
19
|
+
# def self.public_method11;end
|
20
|
+
# protected
|
21
|
+
# def self.protected_method1;end
|
22
|
+
# def self.protected_method2;end
|
23
|
+
# def self.protected_method11;end
|
24
|
+
# private
|
25
|
+
# def self.private_method1;end
|
26
|
+
# def self.private_method2;end
|
27
|
+
# def self.private_method11;end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# method call
|
31
|
+
#
|
32
|
+
# GrepMethod.new.grep_method :public_method1, false # => [:public_method1]
|
33
|
+
# GrepMethod.grep_method :public_method1, false # => [:public_method1]
|
34
|
+
# GrepMethod.new.grep_method /public_method1/, false # => [:public_method1, :public_method11]
|
35
|
+
# GrepMethod.grep_method /public_method1/, false # => [:public_method1, :public_method11]
|
36
|
+
# GrepMethod.new.grep_method /public_method3/, false # => []
|
37
|
+
# GrepMethod.grep_method /public_method3/, false # => []
|
38
|
+
# GrepMethod.new.grep_method :__send__, true # => [:__send__]
|
39
|
+
# GrepMethod.grep_method :__send__, true # => [:__send__]
|
40
|
+
#
|
41
|
+
def grep_method(search, all = true)
|
42
|
+
self.class.grep_method(search, all)
|
43
|
+
end
|
44
|
+
end
|
data/lib/open_classes/object.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'open_classes/object/any_of'
|
4
4
|
require 'open_classes/object/boolean'
|
5
|
+
require 'open_classes/object/grep_method'
|
5
6
|
require 'open_classes/object/grep_public_instance_method'
|
6
7
|
require 'open_classes/object/guard'
|
7
8
|
require 'open_classes/object/method_nameable'
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'tbpgr_utils'
|
4
|
+
|
5
|
+
describe Object do
|
6
|
+
class GrepMethod
|
7
|
+
def self.public_method1; end
|
8
|
+
def self.public_method2; end
|
9
|
+
def self.public_method11; end
|
10
|
+
protected
|
11
|
+
def self.protected_method1; end
|
12
|
+
def self.protected_method2; end
|
13
|
+
def self.protected_method11; end
|
14
|
+
private
|
15
|
+
def self.private_method1; end
|
16
|
+
def self.private_method2; end
|
17
|
+
def self.private_method11; end
|
18
|
+
end
|
19
|
+
|
20
|
+
context :grep_public_instance_method do
|
21
|
+
cases = [
|
22
|
+
{
|
23
|
+
case_no: 1,
|
24
|
+
case_title: 'String case',
|
25
|
+
search: 'public_method1',
|
26
|
+
all: false,
|
27
|
+
expected: [:public_method1],
|
28
|
+
},
|
29
|
+
{
|
30
|
+
case_no: 2,
|
31
|
+
case_title: 'Symbol case',
|
32
|
+
search: :public_method1,
|
33
|
+
all: false,
|
34
|
+
expected: [:public_method1],
|
35
|
+
},
|
36
|
+
{
|
37
|
+
case_no: 3,
|
38
|
+
case_title: 'Regexp case',
|
39
|
+
search: /public_method1/,
|
40
|
+
all: false,
|
41
|
+
expected: [:public_method1, :public_method11],
|
42
|
+
},
|
43
|
+
{
|
44
|
+
case_no: 4,
|
45
|
+
case_title: 'not hit case',
|
46
|
+
search: /public_method3/,
|
47
|
+
all: false,
|
48
|
+
expected: [],
|
49
|
+
},
|
50
|
+
{
|
51
|
+
case_no: 5,
|
52
|
+
case_title: 'all case',
|
53
|
+
search: :__send__,
|
54
|
+
all: true,
|
55
|
+
expected: [:__send__],
|
56
|
+
},
|
57
|
+
]
|
58
|
+
|
59
|
+
cases.each do |c|
|
60
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
61
|
+
begin
|
62
|
+
case_before c
|
63
|
+
|
64
|
+
# -- given --
|
65
|
+
# nothing
|
66
|
+
|
67
|
+
# -- when --
|
68
|
+
actual_instance = GrepMethod.new.grep_method c[:search], c[:all]
|
69
|
+
actual_class = GrepMethod.grep_method c[:search], c[:all]
|
70
|
+
|
71
|
+
# -- then --
|
72
|
+
expect(actual_instance).to eq(c[:expected])
|
73
|
+
expect(actual_class).to eq(c[:expected])
|
74
|
+
ensure
|
75
|
+
case_after c
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def case_before(c)
|
80
|
+
# implement each case before
|
81
|
+
end
|
82
|
+
|
83
|
+
def case_after(c)
|
84
|
+
# implement each case after
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.130
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tbpgr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/open_classes/object.rb
|
204
204
|
- lib/open_classes/object/any_of.rb
|
205
205
|
- lib/open_classes/object/boolean.rb
|
206
|
+
- lib/open_classes/object/grep_method.rb
|
206
207
|
- lib/open_classes/object/grep_public_instance_method.rb
|
207
208
|
- lib/open_classes/object/guard.rb
|
208
209
|
- lib/open_classes/object/method_nameable.rb
|
@@ -341,6 +342,7 @@ files:
|
|
341
342
|
- spec/open_classes/numeric/to_oct_table_spec.rb
|
342
343
|
- spec/open_classes/object/any_of_spec.rb
|
343
344
|
- spec/open_classes/object/boolean_spec.rb
|
345
|
+
- spec/open_classes/object/grep_method_spec.rb
|
344
346
|
- spec/open_classes/object/grep_public_instance_method_spec.rb
|
345
347
|
- spec/open_classes/object/guard_spec.rb
|
346
348
|
- spec/open_classes/object/method_nameable_spec.rb
|
@@ -500,6 +502,7 @@ test_files:
|
|
500
502
|
- spec/open_classes/numeric/to_oct_table_spec.rb
|
501
503
|
- spec/open_classes/object/any_of_spec.rb
|
502
504
|
- spec/open_classes/object/boolean_spec.rb
|
505
|
+
- spec/open_classes/object/grep_method_spec.rb
|
503
506
|
- spec/open_classes/object/grep_public_instance_method_spec.rb
|
504
507
|
- spec/open_classes/object/guard_spec.rb
|
505
508
|
- spec/open_classes/object/method_nameable_spec.rb
|