guerrilla_patch 2.8.3 → 2.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -1
- data/README.md +37 -0
- data/lib/guerrilla_patch/kernel.rb +6 -0
- data/lib/guerrilla_patch/version.rb +1 -1
- data/spec/guerrilla_patch/kernel_spec.rb +15 -0
- metadata +4 -5
- data/VERSION +0 -1
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
guerrilla_patch (2.8.
|
4
|
+
guerrilla_patch (2.8.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
+
binding_of_caller (0.7.2)
|
10
|
+
debug_inspector (>= 0.0.1)
|
11
|
+
debug_inspector (0.0.2)
|
9
12
|
diff-lcs (1.1.3)
|
10
13
|
rake (0.9.2.2)
|
11
14
|
rspec (2.8.0)
|
@@ -21,6 +24,7 @@ PLATFORMS
|
|
21
24
|
ruby
|
22
25
|
|
23
26
|
DEPENDENCIES
|
27
|
+
binding_of_caller
|
24
28
|
bundler (>= 1.0.0)
|
25
29
|
guerrilla_patch!
|
26
30
|
rake
|
data/README.md
CHANGED
@@ -5,6 +5,43 @@ Guerrilla Patch
|
|
5
5
|
|
6
6
|
I am tired of hunting and tracking down my own monkey patches. Not to mention hassle of dragging them between projects. I figured gem is a remedy for this.
|
7
7
|
|
8
|
+
Assign instance variables automaticaly
|
9
|
+
---------------------------------------
|
10
|
+
You know that neat coffee script trick that shortens code below.
|
11
|
+
|
12
|
+
```
|
13
|
+
class Animal
|
14
|
+
constructor: (name) ->
|
15
|
+
@name = name
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
To be more succint:
|
20
|
+
|
21
|
+
```
|
22
|
+
class Animal
|
23
|
+
constructor: (@name) ->
|
24
|
+
```
|
25
|
+
|
26
|
+
While waiting for Ruby 2.0 to implement it I am using this:
|
27
|
+
|
28
|
+
````
|
29
|
+
def initialize(amount, index:nil, envy_no_more:nil)
|
30
|
+
auto_assign
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
It's equvalent to this:
|
35
|
+
|
36
|
+
```
|
37
|
+
def initialize(amount, index:nil, envy_no_more:nil)
|
38
|
+
@amount = amount
|
39
|
+
@index = index
|
40
|
+
@envy_no_more = envy_no_more
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
|
8
45
|
BigDecimal
|
9
46
|
-----------
|
10
47
|
Not using BigDecimal is asking for trouble, but using it is way too verbose:
|
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'bigdecimal'
|
2
2
|
require 'guerrilla_patch/allocate'
|
3
|
+
require 'binding_of_caller'
|
3
4
|
|
4
5
|
module Kernel
|
6
|
+
def auto_assign
|
7
|
+
caller_binding = binding.of_caller(1)
|
8
|
+
method(caller[0][/`.*'/][1..-2]).parameters.each { |arg| instance_eval("@#{arg[1]} = caller_binding.eval(arg[1].to_s)") }
|
9
|
+
end
|
10
|
+
|
5
11
|
def let(name, &block)
|
6
12
|
define_method(name, &block)
|
7
13
|
end
|
@@ -80,6 +80,21 @@ describe Kernel do
|
|
80
80
|
33.11.divide({ '1A' => 50, '1B' => 50}).should == {"1A"=> 16.56, "1B"=> 16.55 }
|
81
81
|
end
|
82
82
|
|
83
|
+
class TestAssign
|
84
|
+
attr_reader :index, :amount
|
85
|
+
|
86
|
+
def initialize(index, amount)
|
87
|
+
auto_assign
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'assigns by default' do
|
93
|
+
subject = TestAssign.new(1, 100.0)
|
94
|
+
subject.index.should == 1
|
95
|
+
subject.amount.should == 100.0
|
96
|
+
end
|
97
|
+
|
83
98
|
end
|
84
99
|
|
85
100
|
describe Array do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guerrilla_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.8.
|
4
|
+
version: 2.8.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,7 +27,6 @@ files:
|
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
-
- VERSION
|
31
30
|
- guerrilla_patch.gemspec
|
32
31
|
- guerrilla_patch.sublime-project
|
33
32
|
- lib/guerrilla_patch.rb
|
@@ -58,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
57
|
version: '0'
|
59
58
|
segments:
|
60
59
|
- 0
|
61
|
-
hash:
|
60
|
+
hash: -700366039810131134
|
62
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
62
|
none: false
|
64
63
|
requirements:
|
@@ -67,10 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
66
|
version: '0'
|
68
67
|
segments:
|
69
68
|
- 0
|
70
|
-
hash:
|
69
|
+
hash: -700366039810131134
|
71
70
|
requirements: []
|
72
71
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.23
|
74
73
|
signing_key:
|
75
74
|
specification_version: 3
|
76
75
|
summary: Since I am tired of hunting down monkey patches at large I am caging them
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.8.2
|