fn_space 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/lib/fn_space.rb +32 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ae679420762ed5308515615876b8ba72e9f5869
|
4
|
+
data.tar.gz: afde2f07af6513a319e79c285012c9fe1cdafbfa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f3fbfd0595a4962ebaacebc48bd69f2f4cfc82a249a3ba41e3fb344c91b957714f7ebc7b912fdcaa05c23f90f786f273729b12b6c6c7b6654dd629689d086ba
|
7
|
+
data.tar.gz: dd99a16c6bdda59efcce91afeb048cad1b00fc706ffe5989a8e95ca4c173ca046a41815188e8d008aa6123eced9303b94e990e3fb70918ac748d93b6937471ef
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Max White
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# FnSpace
|
2
|
+
|
3
|
+
A Ruby class for explicit function importing and exporting.
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
require 'fn_space'
|
9
|
+
|
10
|
+
module Foo
|
11
|
+
def self.add(a, b)
|
12
|
+
a + b
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.take(a, b)
|
16
|
+
a - b
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Bar = {
|
21
|
+
times: ->(a, b) { a * b }
|
22
|
+
}
|
23
|
+
|
24
|
+
class FnSpace
|
25
|
+
add, take = import(:add, :take).from 'Foo'
|
26
|
+
times = import(:times).from 'Bar'
|
27
|
+
|
28
|
+
result = ->(a, b) { add.(times.(a, b), take.(a, b)) }
|
29
|
+
|
30
|
+
export(result: result).as 'Sums'
|
31
|
+
end
|
32
|
+
|
33
|
+
Sums[:result].(5, 8) # 37
|
34
|
+
```
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
Add your Gemfile:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
gem 'fn_space'
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. [Fork it]( https://github.com/mushishi78/fn_space/fork)
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/lib/fn_space.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class FnSpace < BasicObject
|
2
|
+
def self.import(*names)
|
3
|
+
Importer.new(names)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.export(obj)
|
7
|
+
Exporter.new(obj)
|
8
|
+
end
|
9
|
+
|
10
|
+
class Importer
|
11
|
+
def initialize(names)
|
12
|
+
@names = names
|
13
|
+
end
|
14
|
+
|
15
|
+
def from(constant)
|
16
|
+
obj = ::Object.const_get(constant)
|
17
|
+
is_hash = obj.respond_to?(:has_key?)
|
18
|
+
functions = @names.map { |m| is_hash ? obj[m].to_proc : obj.method(m) }
|
19
|
+
functions.length == 1 ? functions.first : functions
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Exporter
|
24
|
+
def initialize(obj)
|
25
|
+
@obj = obj
|
26
|
+
end
|
27
|
+
|
28
|
+
def as(constant)
|
29
|
+
::Object.const_set(constant, @obj)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fn_space
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max White
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: mushishi78@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE.txt
|
20
|
+
- README.md
|
21
|
+
- lib/fn_space.rb
|
22
|
+
homepage: https://github.com/mushishi78/fn_space
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.8
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A Ruby class for explicit function importing and exporting
|
46
|
+
test_files: []
|