daberu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -4
- data/lib/daberu.rb +3 -1
- data/lib/daberu/version.rb +1 -1
- data/spec/daberu_spec.rb +26 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
おしゃべりなオブジェクトをつくることができます。
|
4
4
|
[You can create a talkative object.]
|
5
5
|
|
6
|
+
メソッドが呼ばれると、その情報を指定されたフォーマットで出力します。
|
7
|
+
[If a method is called, it will output in the format which had the information specified.]
|
8
|
+
|
6
9
|
主な用途:デバッグ
|
7
10
|
[One way, Debugging.]
|
8
11
|
|
@@ -25,17 +28,30 @@ Or install it yourself as:
|
|
25
28
|
require 'daberu'
|
26
29
|
|
27
30
|
a = Daberu.new([])
|
28
|
-
a << 1 #=> "Method: <<, Arguments: [1], Block: "
|
29
|
-
a << 2 #=> "Method: <<, Arguments: [2], Block: "
|
30
|
-
a << 3 #=> "Method: <<, Arguments: [3], Block: "
|
31
|
+
a << 1 #=> "Class: Array, Method: <<, Arguments: [1], Block: "
|
32
|
+
a << 2 #=> "Class: Array, Method: <<, Arguments: [2], Block: "
|
33
|
+
a << 3 #=> "Class: Array, Method: <<, Arguments: [3], Block: "
|
31
34
|
a.each do |i|
|
32
35
|
p i
|
33
36
|
end
|
34
|
-
#=> "Method: each, Arguments: [], Block: #<Proc:...>"
|
37
|
+
#=> "Class: Array, Method: each, Arguments: [], Block: #<Proc:...>"
|
35
38
|
1
|
36
39
|
2
|
37
40
|
3
|
38
41
|
|
42
|
+
p a.format #=> "Class: %s, Method: %s, Arguments: [%s], Block: %s"
|
43
|
+
a.format = "%s#%s(%s)"
|
44
|
+
p a.format #=> "%s#%s(%s)"
|
45
|
+
a << 4 #=> "Array#<<(4)"
|
46
|
+
|
47
|
+
### Ruby version
|
48
|
+
|
49
|
+
開発/テストは1.9系で行なっています。
|
50
|
+
[Development and Testing on 1.9.x.]
|
51
|
+
|
52
|
+
1.8系でも動作しますが、ドキュメントと挙動が違うかもしれません。
|
53
|
+
[Although 1.8.x operates, an action may differ from documents.]
|
54
|
+
|
39
55
|
## Contributing
|
40
56
|
|
41
57
|
1. Fork it
|
data/lib/daberu.rb
CHANGED
@@ -5,12 +5,14 @@ class Daberu
|
|
5
5
|
undef_method m unless m.to_s =~ /^__|method_missing|respond_to?|object_id/
|
6
6
|
end
|
7
7
|
|
8
|
+
attr_accessor :format
|
8
9
|
def initialize(obj = Object.new)
|
9
10
|
@obj = obj
|
11
|
+
@format = "Class: %s, Method: %s, Arguments: [%s], Block: %s"
|
10
12
|
end
|
11
13
|
|
12
14
|
def method_missing(name, *args, &block)
|
13
|
-
p
|
15
|
+
p @format % [@obj.class, name, args.to_s.gsub(/^\[|\]$/, ""), block]
|
14
16
|
@obj.send(name, *args, &block)
|
15
17
|
end
|
16
18
|
end
|
data/lib/daberu/version.rb
CHANGED
data/spec/daberu_spec.rb
CHANGED
@@ -42,8 +42,8 @@ describe Daberu do
|
|
42
42
|
$stdout = STDOUT
|
43
43
|
File.open(t) {|f|
|
44
44
|
lines = f.read.split(/\n/)
|
45
|
-
lines[0].should =~ /Method: <<, Arguments: \[(\\)*"a(\\)*"\], Block: /
|
46
|
-
lines[1].should =~ /Method: each, Arguments: \[\], Block: #<Proc:/
|
45
|
+
lines[0].should =~ /Class: Array, Method: <<, Arguments: \[(\\)*"a(\\)*"\], Block: /
|
46
|
+
lines[1].should =~ /Class: Array, Method: each, Arguments: \[\], Block: #<Proc:/
|
47
47
|
}
|
48
48
|
end
|
49
49
|
|
@@ -56,8 +56,31 @@ describe Daberu do
|
|
56
56
|
$stdout = STDOUT
|
57
57
|
File.open(t) {|f|
|
58
58
|
lines = f.read.split(/\n/)
|
59
|
-
lines[0].should =~ /Method: class, Arguments: \[\], Block: /
|
59
|
+
lines[0].should =~ /Class: Object, Method: class, Arguments: \[\], Block: /
|
60
60
|
}
|
61
61
|
end
|
62
|
+
|
63
|
+
it "is point of stdout format" do
|
64
|
+
t = Tempfile.open("daberu")
|
65
|
+
$stdout = File.open(t, "w")
|
66
|
+
d = Daberu.new
|
67
|
+
d.format = "%s#%s(%s): %s"
|
68
|
+
d.class
|
69
|
+
$stdout.flush
|
70
|
+
$stdout = STDOUT
|
71
|
+
File.open(t) {|f|
|
72
|
+
lines = f.read.split(/\n/)
|
73
|
+
lines[0].should =~ /Object#class\(\): /
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is view of stdout format" do
|
78
|
+
t = Tempfile.open("daberu")
|
79
|
+
$stdout = File.open(t, "w")
|
80
|
+
d = Daberu.new
|
81
|
+
$stdout.flush
|
82
|
+
$stdout = STDOUT
|
83
|
+
d.format.should == "Class: %s, Method: %s, Arguments: [%s], Block: %s"
|
84
|
+
end
|
62
85
|
end
|
63
86
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daberu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Create a talkative object.
|
15
15
|
email:
|