canada 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/canada.rb +28 -16
- data/lib/canada/version.rb +1 -1
- data/test/canada_test.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f2804cc192f2768996a53201950ede6b51ca617
|
4
|
+
data.tar.gz: 5e0ef95b37b86da47626fdf502842734f8af9acf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d109bf6159a1925e6a3056f4fb1ed2339c7df6653b334dda91023cd14294f64d30a691bd860ecbc96e14ecf1f8344d83fbc02e7cafbef6f79ca21aa648ba2a18
|
7
|
+
data.tar.gz: 9fb080a74ffe0708ad6b6670c97569cb19fdc5821e9b2df4ec5d29b52babbe9578e54ea3b3dc51af5822eab91bcaa38212faba4f0513fe2184e25b225431a001
|
data/README.md
CHANGED
@@ -15,6 +15,10 @@ It's well known that we have [different conventions](http://programmers.stackexc
|
|
15
15
|
=> true
|
16
16
|
>> aboot Object.new
|
17
17
|
=> "#<Object:0x007f802b8b92c0>"
|
18
|
+
>> raise "something went wrong..."
|
19
|
+
RuntimeError: I'm sorry, but something went wrong...
|
20
|
+
from (irb):6
|
21
|
+
from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'
|
18
22
|
```
|
19
23
|
|
20
24
|
Cool, eh?
|
@@ -23,9 +27,9 @@ Cool, eh?
|
|
23
27
|
|
24
28
|
Yes.
|
25
29
|
|
26
|
-
## What about
|
30
|
+
## What about performance?
|
27
31
|
|
28
|
-
We tuned the gem's
|
32
|
+
We hand-tuned the gem's performance to keep it in line with everything else in Canada.
|
29
33
|
|
30
34
|
## Installation
|
31
35
|
|
@@ -48,3 +52,7 @@ Or install it yourself as:
|
|
48
52
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
53
|
4. Push to the branch (`git push origin my-new-feature`)
|
50
54
|
5. Create new Pull Request
|
55
|
+
|
56
|
+
## Product of Canada
|
57
|
+
|
58
|
+
This gem is a 100% Canadian product. We hack on open-source projects like this every other Tuesday at [#VANRUBY](http://vanruby.org). If you would like to join us, check out our [meetup page](http://www.meetup.com/vancouver-ruby/) for details.
|
data/lib/canada.rb
CHANGED
@@ -1,27 +1,39 @@
|
|
1
1
|
require "canada/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Canada
|
4
|
+
module ObjectExtensions
|
5
|
+
EH_METHOD_REGEXP = /\A(?<method_name>.+)_eh\?\z/
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def respond_to_missing?(meth, include_all = false)
|
8
|
+
if (m = EH_METHOD_REGEXP.match(meth))
|
9
|
+
super || self.respond_to?("#{m[:method_name]}?", include_all)
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(meth, *args, &block)
|
16
|
+
if (m = EH_METHOD_REGEXP.match(meth))
|
17
|
+
self.public_send("#{m[:method_name]}?", *args, &block)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
super
|
24
|
+
::Object.send(:include, ObjectExtensions)
|
25
|
+
|
26
|
+
module ExceptionExtensions
|
27
|
+
def to_s
|
28
|
+
"I'm sorry, but #{super}"
|
19
29
|
end
|
20
30
|
end
|
21
|
-
end
|
22
31
|
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
::Exception.send(:prepend, ExceptionExtensions)
|
33
|
+
|
34
|
+
module ::Kernel
|
35
|
+
def aboot(obj)
|
36
|
+
obj.inspect
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
data/lib/canada/version.rb
CHANGED
data/test/canada_test.rb
CHANGED
@@ -37,4 +37,9 @@ class CanadaTest < MiniTest::Test
|
|
37
37
|
|
38
38
|
cases.each { |c| assert_equal c.inspect, aboot(c) }
|
39
39
|
end
|
40
|
+
|
41
|
+
def test_exceptions_to_s
|
42
|
+
assert_equal "I'm sorry, but something went wrong...", Exception.new("something went wrong...").to_s
|
43
|
+
assert_equal "I'm sorry, but something went wrong...", Exception.new("something went wrong...").message
|
44
|
+
end
|
40
45
|
end
|