method_composition 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/method_composition.rb +24 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e231670a47dfbdf6f4a95accf9484073e633c32ad9d58e64f97c6d548f338ac
4
+ data.tar.gz: c3db735bfd3ac6bca9286a69f3469b9fa4a425805ef1a1972058bdd37ff9eb59
5
+ SHA512:
6
+ metadata.gz: e6a0c3a6801fc2af9a20dbfefd36be96a25bc5da9b46b33fdba3a16003a77af49f619a49364e5e7e9fd2b0aa8e1b9b5eb99d4992a9c82441e9d1d6939aba723e
7
+ data.tar.gz: 3ced0beeaa154e0906ce783aa353bbd584a3a7dcecedc6a76a8e9ab45aa4f92a6b18dba9724c29f8e9cc3231b12015677ffb803967a28554ef2be76290bad29c
@@ -0,0 +1,24 @@
1
+ module MethodComposition
2
+ module ClassMethods
3
+ def call(*params)
4
+ new.call(*params)
5
+ end
6
+
7
+ def methods_chain(*m_chain)
8
+ (chain << m_chain).flatten!
9
+ end
10
+
11
+ def chain
12
+ @chain ||= []
13
+ end
14
+ end
15
+
16
+ def self.included(base)
17
+ base.extend(ClassMethods)
18
+ end
19
+
20
+ def call(*params)
21
+ result_proc = self.class.chain.map { |mtd| method(mtd) }
22
+ result_proc.reduce(:>>).call(*params)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: method_composition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - mdziardziel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Do you know function composition e.g. from elixir? Now
14
+ you can easily build classes based on this future! Just include
15
+ MethodComposition module and define methods fire order using methods_chain method.
16
+ email:
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/method_composition.rb
22
+ homepage: https://rubygems.org/gems/method_composition
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ source_code_uri: https://github.com/mdziardziel/method_composition
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: build classes based on function(method) composition
46
+ test_files: []