attach_function 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -26
- data/attach_function.gemspec +2 -2
- data/lib/attach_function/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13ee26dfe343552e2bc5fd7807e08afab1a03bd4
|
4
|
+
data.tar.gz: 93789012ea84d1177721e0ec6b851e473816bee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132e09d24a243b0624269cc0d22dfab4959f8f36371d007acf829a0d3a4449d7153da4661d18c3c8a1ab6504da7096df9edb28207ed76cb7705d7fafd93c88fc
|
7
|
+
data.tar.gz: 41cb13978e31d6aa13df7188376a4603df519a04e93d890726d7f0ea9bc42399bffc121488674452f956aaa5b022c8fbd383735ef403dd07d0d02aac5d6b93f7
|
data/README.md
CHANGED
@@ -8,34 +8,35 @@ the user-specified name is not the same as the basename of the target function,
|
|
8
8
|
if the user-specified name is the same as the basename of the parameter.
|
9
9
|
|
10
10
|
## Usage Example:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
11
|
+
```ruby
|
12
|
+
require 'attach_function'
|
13
|
+
|
14
|
+
module Math
|
15
|
+
|
16
|
+
#This will contain the method versions of the functions defined in the Math module
|
17
|
+
module MethodVersions
|
18
|
+
#Get the attach_function macro
|
19
|
+
extend AttachFunction
|
20
|
+
#Apply it to all methods of the Math module that aren't Object methods
|
21
|
+
(Math.methods - Object.methods).each do |m|
|
22
|
+
puts "Attaching #{m}"
|
23
|
+
attach_function m
|
26
24
|
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#Now we include the Math::MethodVersions in Numeric
|
29
|
+
Numeric.include(Math::MethodVersions)
|
30
|
+
#And now we can do this:
|
31
|
+
p "3.14.sin = #{3.14.sin}"
|
32
|
+
p "10.log = #{10.log10}"
|
33
|
+
p "4.sqrt = #{4.sqrt}"
|
34
|
+
```
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
p "10.log = #{10.log10}"
|
33
|
-
p "4.sqrt = #{4.sqrt}"
|
34
|
-
|
35
|
-
#The functionality that has been added to Numeric in this way is contained in the Math::MethodVersions mixin.
|
36
|
-
#I consider this much nicer than rudely monkepatching methods right onto a core class.
|
37
|
-
#This way, library users can see (in pry, for example, or via introspection) where a certain added method came from, and possibly filter it out.
|
38
|
-
#(Ruby doesn't currently support unmixing).
|
36
|
+
#The functionality that has been added to Numeric in this way is contained in the Math::MethodVersions mixin.
|
37
|
+
#I consider this much nicer than rudely monkepatching methods right onto a core class.
|
38
|
+
#This way, library users can see (in pry, for example, or via introspection) where a certain added method came from, and possibly filter it out.
|
39
|
+
#(Ruby doesn't currently support unmixing).
|
39
40
|
|
40
41
|
|
41
42
|
See the specs and the example folder for more examples.
|
data/attach_function.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.name = gem.name
|
15
15
|
spec.version = (gem.module)::VERSION
|
16
|
-
spec.summary = %q{
|
17
|
-
spec.description = %q{
|
16
|
+
spec.summary = %q{Macro to attach a module function to an object by fixing its first argument to self}
|
17
|
+
spec.description = %q{Macro to attach a module function to an object by fixing its first argument to self}
|
18
18
|
|
19
19
|
spec.authors = ["Petr Skocik"]
|
20
20
|
spec.email = ["pskocik@gmail.com"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attach_function
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Skocik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,8 +94,8 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
|
97
|
+
description: Macro to attach a module function to an object by fixing its first argument
|
98
|
+
to self
|
99
99
|
email:
|
100
100
|
- pskocik@gmail.com
|
101
101
|
executables: []
|
@@ -138,7 +138,8 @@ rubyforge_project:
|
|
138
138
|
rubygems_version: 2.2.1
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
|
-
summary:
|
141
|
+
summary: Macro to attach a module function to an object by fixing its first argument
|
142
|
+
to self
|
142
143
|
test_files:
|
143
144
|
- spec/attach_function_spec.rb
|
144
145
|
- spec/spec_helper.rb
|