wtf_methods 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wtf_methods.rb +38 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09020cc081e45b6667cd471df1b347502fa0be1b
4
- data.tar.gz: 284d4e3c9c9f04785e5b1d75d6c26b5d50f88583
3
+ metadata.gz: 381c8f5f6308da4b67e8c77b1818190d6178332b
4
+ data.tar.gz: c970c4af5113562c45c6b2daf77508f31acb34d2
5
5
  SHA512:
6
- metadata.gz: c1ad22e10983e670341b12c37e1951250b587315c4f73ea5396c946263bd987aab490c8653c664bf00d723636771e4c7cf39d554022b7d3373d3c0347dd8ff96
7
- data.tar.gz: 0f27c0bf85c9c1ecac3c3d8fedb9cd13b9e619efed17a223d7d1bcf454614bed1eade170694ea64b7019e5eff7c1388ddef905e60b78fc9268fc134b7fc8f2dd
6
+ metadata.gz: a4c0443ed9e3350707b5228de92275f979a7e2a2dbf359b147b4aa0c0ced7bdbfbf260431c3eca0f28e932645363a9733d09fa74022e35dc44c7e40d77ff14d0
7
+ data.tar.gz: a36496548b5e4fc1dc703e28a3125543f1020e13e5c8c5bd8480f97db9d5cfaa60685622b7408296baca72a0feb84534cba1992ae85b13fedf5a23ca846f3cd2
data/lib/wtf_methods.rb CHANGED
@@ -2,28 +2,55 @@
2
2
  class Object
3
3
  def wtf(class_name)
4
4
 
5
- method_array = []
6
-
7
5
  if defined?(ActiveRecord::Base)
8
- target_methods = class_name.methods - ActiveRecord::Base.methods
6
+ excluded_methods = ActiveRecord::Base.methods
9
7
  else
10
- target_methods = class_name.methods - Object.methods
8
+ excluded_methods = Object.methods
11
9
  end
12
10
 
13
- target_methods.sort.each do |method|
14
- if method_array.first && method[0] >= "a" && method[0] != method_array.last[1]
15
- method_array << "--------------------"
16
- end
17
- method_array << " #{method}"
11
+ class_methods = class_name.methods - excluded_methods
12
+ instance_methods = class_name.instance_methods - excluded_methods
13
+
14
+ puts "===================="
15
+ puts " CLASS METHODS"
16
+ puts "--------------------"
17
+
18
+ if class_methods.empty?
19
+ puts " [none]"
20
+ else
21
+ puts format_methods(class_methods)
18
22
  end
19
23
 
20
24
  puts "===================="
21
- if method_array.empty?
25
+ puts " INSTANCE METHODS"
26
+ puts "--------------------"
27
+
28
+ if instance_methods.empty?
22
29
  puts " [none]"
23
30
  else
24
- puts method_array
31
+ puts format_methods(instance_methods)
25
32
  end
33
+
26
34
  puts "===================="
27
35
 
28
36
  end
37
+
38
+ def format_methods(methods)
39
+
40
+ method_array = []
41
+
42
+ methods.sort.each do |method|
43
+ if method_array.first && method[0] >= "a" && method[0] != method_array.last[1]
44
+ method_array << "--------------------"
45
+ end
46
+ if method_array.last && method[0..-2] == method_array.last[1..-1] && method[-1] == "!"
47
+ method_array[-1] = " #{method[0..-2]}(!)"
48
+ else
49
+ method_array << " #{method}"
50
+ end
51
+ end
52
+
53
+ return method_array
54
+
55
+ end
29
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wtf_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stelios Constantinides
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Prints a formatted list of class-specific methods, excluding ActiveRecord::Base
14
14
  (when applicable) and generic Object methods. See the documentation for examples.