fuby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/fuby.gemspec +1 -1
- data/lib/fuby/alias_method.rb +26 -2
- data/lib/fuby/alias_singleton_method.rb +20 -0
- data/lib/fuby/ancestors.rb +12 -0
- data/lib/fuby/cardinality.rb +27 -0
- data/lib/fuby/curry_eval.rb +19 -0
- data/lib/fuby/deep_const_get.rb +13 -0
- data/lib/fuby/deep_each.rb +21 -6
- data/lib/fuby/define.rb +1 -0
- data/lib/fuby/define_missing_method.rb +13 -23
- data/lib/fuby/define_tok.rb +2 -0
- data/lib/fuby/descendants.rb +3 -4
- data/lib/fuby/eastern_name.rb +11 -0
- data/lib/fuby/enumerables.rb +7 -0
- data/lib/fuby/eql_componentwise.rb +7 -4
- data/lib/fuby/equivalence.rb +7 -4
- data/lib/fuby/eval.rb +1 -51
- data/lib/fuby/extend.rb +15 -4
- data/lib/fuby/first.rb +9 -0
- data/lib/fuby/hash_eval.rb +32 -0
- data/lib/fuby/include.rb +14 -3
- data/lib/fuby/invert.rb +10 -7
- data/lib/fuby/last.rb +9 -0
- data/lib/fuby/longest_common.rb +1 -15
- data/lib/fuby/longest_common_prefix.rb +11 -0
- data/lib/fuby/longest_common_suffix.rb +11 -0
- data/lib/fuby/matches.rb +12 -4
- data/lib/fuby/matches_componentwise.rb +11 -4
- data/lib/fuby/matches_part_of.rb +9 -5
- data/lib/fuby/matches_prefix_of.rb +6 -1
- data/lib/fuby/matches_suffix_of.rb +3 -0
- data/lib/fuby/method_added_as_binary_operator.rb +3 -1
- data/lib/fuby/method_added_as_filter.rb +1 -1
- data/lib/fuby/names.rb +9 -0
- data/lib/fuby/outer_module.rb +18 -0
- data/lib/fuby/part_of.rb +4 -0
- data/lib/fuby/pop.rb +3 -2
- data/lib/fuby/prefix_of.rb +5 -4
- data/lib/fuby/prepend.rb +12 -3
- data/lib/fuby/reject.rb +19 -0
- data/lib/fuby/select.rb +19 -0
- data/lib/fuby/self_and_descendants.rb +1 -3
- data/lib/fuby/send.rb +24 -0
- data/lib/fuby/shift.rb +3 -2
- data/lib/fuby/singleton_method_defined.rb +9 -0
- data/lib/fuby/subclass.rb +2 -2
- data/lib/fuby/submodule.rb +2 -2
- data/lib/fuby/suffix_of.rb +2 -6
- data/lib/fuby/take_until.rb +5 -0
- data/lib/fuby/take_while.rb +8 -0
- data/lib/fuby/to_camel_case.rb +1 -1
- data/lib/fuby/to_dot_case.rb +26 -0
- data/lib/fuby/to_hash.rb +8 -14
- data/lib/fuby/to_slash_case.rb +26 -0
- data/lib/fuby/tok.rb +0 -1
- data/lib/fuby/try_each.rb +1 -0
- data/lib/fuby/try_eval.rb +1 -0
- data/lib/fuby/unshift_options.rb +1 -0
- data/lib/fuby/western_name.rb +11 -0
- data/test/fuby/alias_method.rb +2 -2
- data/test/fuby/ancestors.rb +41 -0
- data/test/fuby/cardinality.rb +34 -0
- data/test/fuby/curry_eval.rb +3 -0
- data/test/fuby/deep.rb +1 -0
- data/test/fuby/deep_each.rb +22 -0
- data/test/fuby/define.rb +1 -0
- data/test/fuby/define_tok.rb +3 -0
- data/test/fuby/descendants.rb +56 -0
- data/test/fuby/drop_until.rb +18 -18
- data/test/fuby/drop_while.rb +18 -18
- data/test/fuby/each.rb +1 -0
- data/test/fuby/eql.rb +1 -0
- data/test/fuby/eql_componentwise.rb +4 -0
- data/test/fuby/equivalence.rb +14 -0
- data/test/fuby/eval.rb +1 -0
- data/test/fuby/extend.rb +1 -1
- data/test/fuby/format.rb +3 -0
- data/test/fuby/hash_eval.rb +3 -0
- data/test/fuby/include.rb +1 -1
- data/test/fuby/index_or_key.rb +3 -0
- data/test/fuby/invert.rb +22 -0
- data/test/fuby/longest_common.rb +1 -0
- data/test/fuby/longest_common_prefix.rb +3 -0
- data/test/fuby/longest_common_suffix.rb +3 -0
- data/test/fuby/matches.rb +5 -0
- data/test/fuby/matches_part_of.rb +3 -0
- data/test/fuby/matches_prefix_of.rb +3 -0
- data/test/fuby/matches_suffix_of.rb +3 -0
- data/test/fuby/new.rb +19 -0
- data/test/fuby/part_of.rb +5 -0
- data/test/fuby/prefix_of.rb +5 -0
- data/test/fuby/prepend.rb +1 -1
- data/test/fuby/private.rb +3 -0
- data/test/fuby/protected.rb +3 -0
- data/test/fuby/public.rb +3 -0
- data/test/fuby/push.rb +1 -0
- data/test/fuby/random.rb +3 -0
- data/test/fuby/self_and_descendants.rb +3 -0
- data/test/fuby/shift.rb +5 -0
- data/test/fuby/shift_if.rb +3 -0
- data/test/fuby/shift_options.rb +3 -0
- data/test/fuby/shift_unless.rb +3 -0
- data/test/fuby/shift_until.rb +3 -0
- data/test/fuby/shift_while.rb +3 -0
- data/test/fuby/splat.rb +3 -0
- data/test/fuby/strip.rb +3 -0
- data/test/fuby/suffix_of.rb +5 -0
- data/test/fuby/take.rb +5 -0
- data/test/fuby/take_until.rb +3 -0
- data/test/fuby/take_while.rb +3 -0
- data/test/fuby/to_components.rb +3 -0
- data/test/fuby/to_dot_case.rb +15 -0
- data/test/fuby/to_slash_case.rb +15 -0
- data/test/fuby/to_tok.rb +3 -0
- data/test/fuby/tok.rb +1 -0
- data/test/fuby/tok_arity.rb +3 -0
- data/test/fuby/tok_direction.rb +3 -0
- data/test/fuby/tok_parity.rb +3 -0
- data/test/fuby/tok_side.rb +3 -0
- data/test/fuby/try.rb +52 -52
- data/test/fuby/try_each.rb +1 -1
- data/test/fuby/try_eval.rb +2 -2
- data/test/fuby/unshift.rb +3 -0
- data/test/fuby/unshift_options.rb +3 -0
- metadata +50 -24
- data/lib/fuby/attributes.rb +0 -15
- data/lib/fuby/class_attributes.rb +0 -37
- data/lib/fuby/dimension.rb +0 -23
- data/lib/fuby/instance_attributes.rb +0 -37
- data/lib/fuby/try_exec.rb +0 -16
- data/test/fuby/attributes.rb +0 -0
- data/test/fuby/class_attributes.rb +0 -0
- data/test/fuby/dimension.rb +0 -0
- data/test/fuby/instance_attributes.rb +0 -0
- data/test/fuby/try_exec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c58761ffc821d904ee1c2daff32e6fa90b41391d
|
4
|
+
data.tar.gz: c5ed1e2783e92b839030973886f7f84e3ef56101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99adb7c87f4ad65b9d7b7c1887f4a44db596c672ae11b3087a8fffe4b080e61dd0d090b4deb50b048ee1132244dd2d9b9ac9214ad5f7777ddf43d3372d3dd70
|
7
|
+
data.tar.gz: 690ee73a4b0d9e26d2578977d975e558913ed50793c6ee866beb820f2a10a43f44741623a2c0a531330288897830a51937711cb74e3b1bae4388748ab39f2805
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ TODO: Write usage instructions here
|
|
23
23
|
## Contributing
|
24
24
|
|
25
25
|
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
2. Create your feature branch prefixed with your handle (`git checkout -b me/my-new-feature`)
|
27
27
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
4. Push to the branch (`git push origin me/my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/fuby.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.version = version
|
12
12
|
gem.license = "MIT"
|
13
13
|
gem.authors = ["Alex Goldsmith"]
|
14
|
-
gem.email = ["alex.
|
14
|
+
gem.email = ["alex.tosyx@gmail.com"]
|
15
15
|
gem.summary = "Lightweight extensions to the Ruby standard library"
|
16
16
|
gem.description = "Lightweight extensions to the Ruby standard library provided by the refinements mechanism."
|
17
17
|
gem.homepage = "http://github.com/tosyx/fuby"
|
data/lib/fuby/alias_method.rb
CHANGED
@@ -1,10 +1,34 @@
|
|
1
|
+
require_relative 'send'
|
1
2
|
require_relative 'uuid'
|
2
3
|
|
3
4
|
module Fuby
|
4
5
|
refine ::Module do
|
5
6
|
|
6
|
-
def alias_method
|
7
|
-
|
7
|
+
def alias_method *sig
|
8
|
+
case sig.length
|
9
|
+
when 1
|
10
|
+
sig.unshift new_name = Symbol.__uuid__
|
11
|
+
self.send :alias_method, *sig
|
12
|
+
new_name
|
13
|
+
when 2
|
14
|
+
self.send :alias_method, *sig
|
15
|
+
else raise new TypeError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
class Send
|
21
|
+
|
22
|
+
def alias_method *sig
|
23
|
+
case sig.length
|
24
|
+
when 1
|
25
|
+
sig.unshift new_name = Symbol.__uuid__
|
26
|
+
@self.send :alias_method, *sig
|
27
|
+
new_name
|
28
|
+
when 2
|
29
|
+
@self.send :alias_method, *sig
|
30
|
+
else raise new TypeError
|
31
|
+
end
|
8
32
|
end
|
9
33
|
|
10
34
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'send'
|
2
|
+
require_relative 'uuid'
|
3
|
+
|
4
|
+
module Fuby
|
5
|
+
refine ::Module do
|
6
|
+
|
7
|
+
def alias_singleton_method *sig
|
8
|
+
case sig.length
|
9
|
+
when 1
|
10
|
+
sig.unshift new_name = Symbol.__uuid__
|
11
|
+
self.singleton_class.send :alias_method, *sig
|
12
|
+
new_name
|
13
|
+
when 2
|
14
|
+
self.singleton_class.send :alias_method, *sig
|
15
|
+
else raise new TypeError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fuby
|
2
|
+
refine ::Module do
|
3
|
+
|
4
|
+
def ancestors type = nil
|
5
|
+
super().tap { |mods| return mods.select { |mod| type === mod } if type }
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
12
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'enumerables'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::Object do
|
5
|
+
|
6
|
+
def cardinality
|
7
|
+
1
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
refine ::NilClass do
|
12
|
+
|
13
|
+
def cardinality
|
14
|
+
0
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
Enumerables.each do |enumerable|
|
19
|
+
refine enumerable do
|
20
|
+
|
21
|
+
def cardinality
|
22
|
+
count
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'intercept'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::Object do
|
5
|
+
|
6
|
+
def curry_eval *pre, &shell
|
7
|
+
|
8
|
+
if Hash === pre.last
|
9
|
+
defaults = pre.pop
|
10
|
+
intercept { |*sig, &blk| send *pre, sig, (sig.pop_options defaults), &blk }
|
11
|
+
|
12
|
+
else
|
13
|
+
intercept { |*sig, &blk| send *pre, &blk }
|
14
|
+
|
15
|
+
end.instance_exec self, &shell
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/fuby/deep_each.rb
CHANGED
@@ -1,12 +1,27 @@
|
|
1
|
+
require_relative 'each_with_index_or_key'
|
2
|
+
require_relative 'enumerables'
|
3
|
+
|
1
4
|
module Fuby
|
2
|
-
|
5
|
+
Enumerables.each do |enumerable|
|
6
|
+
refine enumerable do
|
7
|
+
|
8
|
+
def deep_each *path, &blk
|
9
|
+
if block_given?
|
10
|
+
|
11
|
+
each_with_index_or_key do |e, i|
|
12
|
+
next e.deep_each i, *path, &blk if self.class === e
|
13
|
+
next yield e, i, *path
|
14
|
+
end
|
15
|
+
|
16
|
+
else
|
3
17
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
18
|
+
::Enumerator.new do |result|
|
19
|
+
deep_each { |e, *path| result.<< e, *path }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
8
23
|
end
|
9
|
-
end
|
10
24
|
|
25
|
+
end
|
11
26
|
end
|
12
27
|
end
|
data/lib/fuby/define.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
@@ -1,33 +1,23 @@
|
|
1
1
|
require_relative 'uuid'
|
2
|
+
require_relative 'send'
|
3
|
+
require_relative 'include'
|
4
|
+
require_relative 'prepend'
|
2
5
|
|
3
6
|
module Fuby
|
4
7
|
refine ::Module do
|
5
|
-
protected
|
6
8
|
|
7
9
|
def define_missing_method missing_reg, &missing_blk
|
8
|
-
mod = self
|
9
|
-
|
10
10
|
send :define_method, missing_method = Symbol.__uuid__, &missing_blk
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
mod.send
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
send key, *sig, &blk
|
24
|
-
end
|
25
|
-
|
26
|
-
alias_method was_respond_to = Symbol.__uuid__, :respond_to?
|
27
|
-
|
28
|
-
define_method :respond_to? do |key|
|
29
|
-
missing_reg === key or send was_respond_to, key
|
30
|
-
end
|
11
|
+
prepend {
|
12
|
+
mod = self
|
13
|
+
mod.send.define_method(:method_missing) { |key, *sig, &blk|
|
14
|
+
return super key, *sig, &blk unless matched_sig = missing_reg.match(key)
|
15
|
+
matched_sig = matched_sig.to_a.drop 1
|
16
|
+
mod.send.define_method(key) { |*sig, &blk| send missing_method, *(matched_sig + sig), &blk }
|
17
|
+
send key, *sig, &blk
|
18
|
+
}
|
19
|
+
mod.send.define_method(:respond_to?) { |key| missing_reg === key || super(key) }
|
20
|
+
}
|
31
21
|
end
|
32
22
|
|
33
23
|
end
|
data/lib/fuby/define_tok.rb
CHANGED
data/lib/fuby/descendants.rb
CHANGED
@@ -2,12 +2,11 @@ module Fuby
|
|
2
2
|
refine ::Module do
|
3
3
|
|
4
4
|
def descendants type = ::Module
|
5
|
-
|
6
|
-
ObjectSpace.each_object(type).select { |mod| mod.ancestors.include? self }
|
5
|
+
ObjectSpace.each_object(type).select { |mod| mod < self }
|
7
6
|
end
|
8
7
|
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
|
-
Dir.glob "
|
13
|
-
Dir.glob "*
|
11
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
12
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require_relative 'each_with_index_or_key'
|
2
|
+
require_relative 'enumerables'
|
2
3
|
|
3
4
|
module Fuby
|
4
|
-
|
5
|
+
Enumerables.each do |enumerable|
|
6
|
+
refine enumerable do
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
def eql_componentwise? that
|
9
|
+
each_with_index_or_key.all? { |e, k| e == that[k] }
|
10
|
+
end
|
9
11
|
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/fuby/equivalence.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require_relative 'splat'
|
2
|
+
require_relative 'enumerables'
|
2
3
|
|
3
4
|
module Fuby
|
4
|
-
|
5
|
+
Enumerables.each do |enumerable|
|
6
|
+
refine enumerable do
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
def equivalence? eq = :eql?
|
9
|
+
each_cons(2).splat.all? { |fst, snd| fst.send eq, snd }
|
10
|
+
end
|
9
11
|
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/fuby/eval.rb
CHANGED
@@ -1,51 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Fuby
|
4
|
-
refine ::Hash do
|
5
|
-
|
6
|
-
def hash_eval &body
|
7
|
-
intercept do |key, *sig, &blk|
|
8
|
-
val = self[key]
|
9
|
-
key = key.to_s.chomp!("!").to_sym and self.delete key if /!$/ === key.to_s
|
10
|
-
|
11
|
-
case sig
|
12
|
-
when [] then sig.unshift ({}) if blk
|
13
|
-
when [Object]
|
14
|
-
else raise ::ArgumentError
|
15
|
-
end
|
16
|
-
|
17
|
-
case arg = sig.first
|
18
|
-
when nil then next val
|
19
|
-
when ::Hash
|
20
|
-
self[key] = {} if self[key].nil?
|
21
|
-
self[key].merge! arg
|
22
|
-
self[key].hash_exec &blk if blk
|
23
|
-
else
|
24
|
-
self[key] = arg
|
25
|
-
end
|
26
|
-
|
27
|
-
self[key]
|
28
|
-
end.instance_exec &body
|
29
|
-
end
|
30
|
-
|
31
|
-
alias_method :hash_exec, :hash_eval
|
32
|
-
|
33
|
-
end
|
34
|
-
refine ::Object do
|
35
|
-
|
36
|
-
def curry_eval *pre, &shell
|
37
|
-
|
38
|
-
if Hash === pre.last
|
39
|
-
defaults = pre.pop
|
40
|
-
intercept { |*sig, &blk| send *pre, sig, (sig.pop_options defaults), &blk }
|
41
|
-
|
42
|
-
else
|
43
|
-
intercept { |*sig, &blk| send *pre, &blk }
|
44
|
-
|
45
|
-
end.instance_exec self, &shell
|
46
|
-
end
|
47
|
-
|
48
|
-
alias_method :curry_exec, :curry_eval
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
1
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
data/lib/fuby/extend.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
+
require_relative 'send'
|
2
|
+
|
1
3
|
module Fuby
|
2
|
-
refine ::
|
4
|
+
refine ::Module do
|
3
5
|
|
4
|
-
def extend
|
5
|
-
extend *extends unless extends.empty?
|
6
|
-
extend ::Module.new(&body) if block_given?
|
6
|
+
def extend *extends, &body
|
7
|
+
self.send :extend, *extends unless extends.empty?
|
8
|
+
self.send :extend, ::Module.new(&body) if block_given?
|
7
9
|
self
|
8
10
|
end
|
9
11
|
|
10
12
|
end
|
13
|
+
class Send
|
14
|
+
|
15
|
+
def extend *extends, &body
|
16
|
+
@self.send :extend, *extends unless extends.empty?
|
17
|
+
@self.send :extend, ::Module.new(&body) if block_given?
|
18
|
+
@self
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
11
22
|
end
|
data/lib/fuby/first.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'intercept'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::Hash do
|
5
|
+
|
6
|
+
def hash_eval &body
|
7
|
+
intercept do |key, *sig, &blk|
|
8
|
+
val = self[key]
|
9
|
+
key = key.to_s.chomp!("!").to_sym and self.delete key if /!$/ === key.to_s
|
10
|
+
|
11
|
+
case sig
|
12
|
+
when [] then sig.unshift ({}) if blk
|
13
|
+
when [Object]
|
14
|
+
else raise ::ArgumentError
|
15
|
+
end
|
16
|
+
|
17
|
+
case arg = sig.first
|
18
|
+
when nil then next val
|
19
|
+
when ::Hash
|
20
|
+
self[key] = {} if self[key].nil?
|
21
|
+
self[key].merge! arg
|
22
|
+
self[key].hash_exec &blk if blk
|
23
|
+
else
|
24
|
+
self[key] = arg
|
25
|
+
end
|
26
|
+
|
27
|
+
self[key]
|
28
|
+
end.instance_exec &body
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|