lab42_core 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/lab42/core/fn/array.rb +5 -0
- data/lib/lab42/core/fn/basic_object.rb +27 -0
- data/lib/lab42/core/fn/enumerable.rb +5 -0
- data/lib/lab42/core/fn/enumerator/lazy.rb +7 -0
- data/lib/lab42/core/fn/fm.rb +0 -0
- data/lib/lab42/core/fn/iterator_reimpl.rb +31 -0
- data/lib/lab42/core/fn.rb +21 -0
- data/lib/lab42/core/version.rb +1 -1
- metadata +16 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7f5a0cfaf9792e16c822da9826afaca6cb96cdf
|
4
|
+
data.tar.gz: 194ffc45ea41e84095afa8c0bca479425cf73616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a8af599ac63a9a52c416f8d9aa964cf95f91f6558e5560f5fbe1fbc40679d98f4aa89937011636fdb85cd1d18caaffa8e8593b0f42fb21617c866cbd1ce6b0
|
7
|
+
data.tar.gz: 02f3fa3eeef659ff44f6f552f1f8b47123bbc0484a5df35398041a0b6ec0efcb94b7bee96195495fb8e48e4ac229c11049e5179be9b6a53be52b2374ddac8a20
|
data/README.md
CHANGED
@@ -21,3 +21,19 @@ Ruby Core Module Extensions (in the spirit of lab419/core)
|
|
21
21
|
```ruby
|
22
22
|
{a: 42, b: 43}.only :a, :c # ===> {a: 42}
|
23
23
|
```
|
24
|
+
|
25
|
+
## Fn
|
26
|
+
|
27
|
+
Must be required specifically!
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'lab42/core/fn'
|
31
|
+
|
32
|
+
# Get method of an object
|
33
|
+
printer = Kernel.fn.puts
|
34
|
+
printer.( 42 )
|
35
|
+
2.times(&printer)
|
36
|
+
|
37
|
+
# It also extends some enumerable methods for easier execution
|
38
|
+
%w{hello world}.each printer
|
39
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Lab42
|
2
|
+
module Core
|
3
|
+
class Fn < BasicObject
|
4
|
+
private
|
5
|
+
def initialize source
|
6
|
+
@source = source
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing *args, &blk
|
10
|
+
@source.method args.first
|
11
|
+
end
|
12
|
+
end # class Fn
|
13
|
+
class Fm < BasicObject
|
14
|
+
private
|
15
|
+
def initialize source
|
16
|
+
@source = source
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing *args, &blk
|
20
|
+
m = @source.instance_method args.first
|
21
|
+
-> receiver, *a, &b do
|
22
|
+
m.bind( receiver ).(*a, &b)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end # class Fn
|
26
|
+
end # module Core
|
27
|
+
end # module Lab42
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Lab42
|
2
|
+
module Core
|
3
|
+
module IteratorReimpl
|
4
|
+
def self.included into
|
5
|
+
into.module_eval do
|
6
|
+
alias_method :__lab42_core_iterator_map__, :map
|
7
|
+
def map behavior=nil, &blk
|
8
|
+
__lab42_core_iterator_map__(&(behavior||blk))
|
9
|
+
end
|
10
|
+
alias_method :__lab42_core_iterator_reduce__, :reduce
|
11
|
+
def reduce behavior=nil, &blk
|
12
|
+
if Symbol === behavior
|
13
|
+
__lab42_core_iterator_reduce__ behavior
|
14
|
+
else
|
15
|
+
__lab42_core_iterator_reduce__(&(behavior||blk))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :__lab42_core_iterator_inject__, :inject
|
20
|
+
def inject value, behavior=nil, &blk
|
21
|
+
if Symbol === behavior
|
22
|
+
__lab42_core_iterator_inject__ value, behavior
|
23
|
+
else
|
24
|
+
__lab42_core_iterator_inject__(value, &(behavior||blk))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end # module Core
|
31
|
+
end # module Lab42
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'lab42/core/fn/basic_object'
|
2
|
+
require 'lab42/core/fn/array'
|
3
|
+
require 'lab42/core/fn/enumerable'
|
4
|
+
require 'lab42/core/fn/enumerator/lazy'
|
5
|
+
|
6
|
+
class Object
|
7
|
+
def fn
|
8
|
+
# There can only be one (per instance)
|
9
|
+
@__lab42_core_fn__ ||= Lab42::Core::Fn.new self
|
10
|
+
# But caching in frozen objects is not an option
|
11
|
+
rescue
|
12
|
+
Lab42::Core::Fn.new self
|
13
|
+
end
|
14
|
+
|
15
|
+
def fm
|
16
|
+
@__lab42_core_fm__ ||= Lab42::Core::Fm.new self
|
17
|
+
# But caching in frozen objects is not an option
|
18
|
+
rescue
|
19
|
+
Lab42::Core::Fn.new self
|
20
|
+
end
|
21
|
+
end # class Object
|
data/lib/lab42/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.9.12
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.9.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.13.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.13.0
|
41
41
|
description: Hash, Dir and more extensions
|
@@ -45,8 +45,15 @@ extensions: []
|
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
47
|
- lib/lab42/core.rb
|
48
|
+
- lib/lab42/core/fn/array.rb
|
49
|
+
- lib/lab42/core/fn/basic_object.rb
|
50
|
+
- lib/lab42/core/fn/enumerator/lazy.rb
|
51
|
+
- lib/lab42/core/fn/fm.rb
|
52
|
+
- lib/lab42/core/fn/iterator_reimpl.rb
|
53
|
+
- lib/lab42/core/fn/enumerable.rb
|
48
54
|
- lib/lab42/core/dir.rb
|
49
55
|
- lib/lab42/core/version.rb
|
56
|
+
- lib/lab42/core/fn.rb
|
50
57
|
- lib/lab42/core/hash.rb
|
51
58
|
- lib/lab42/core/kernel.rb
|
52
59
|
- lib/lab42/core/enumerable.rb
|
@@ -62,17 +69,17 @@ require_paths:
|
|
62
69
|
- lib
|
63
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
71
|
requirements:
|
65
|
-
- -
|
72
|
+
- - ">="
|
66
73
|
- !ruby/object:Gem::Version
|
67
74
|
version: 2.0.0
|
68
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
76
|
requirements:
|
70
|
-
- -
|
77
|
+
- - ">="
|
71
78
|
- !ruby/object:Gem::Version
|
72
79
|
version: '0'
|
73
80
|
requirements: []
|
74
81
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.1.
|
82
|
+
rubygems_version: 2.1.5
|
76
83
|
signing_key:
|
77
84
|
specification_version: 4
|
78
85
|
summary: What I am missing in Ruby
|