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
data/lib/fuby/suffix_of.rb
CHANGED
@@ -5,13 +5,9 @@ module Fuby
|
|
5
5
|
eql? that.drop -length
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
matches? that.drop - length
|
10
|
-
end
|
11
|
-
|
12
|
-
method_added_as_binary_operator :suffix_of?, :matches_suffix_of?
|
8
|
+
method_added_as_binary_operator :suffix_of?
|
13
9
|
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
17
|
-
Dir.glob "*
|
13
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
data/lib/fuby/take_until.rb
CHANGED
data/lib/fuby/take_while.rb
CHANGED
data/lib/fuby/to_camel_case.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'to_components'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::String do
|
5
|
+
|
6
|
+
def to_DOT_CASE
|
7
|
+
to_components.join('.').upcase
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_dot_case
|
11
|
+
to_components.join('.').downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
refine ::Symbol do
|
16
|
+
|
17
|
+
def to_DOT_CASE
|
18
|
+
@to_DOT_CASE ||= to_s.to_DOT_CASE.to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_dot_case
|
22
|
+
@to_dot_case ||= to_s.to_dot_case.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/fuby/to_hash.rb
CHANGED
@@ -1,25 +1,19 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'enumerables'
|
2
2
|
require_relative 'each_with_index_or_key'
|
3
3
|
|
4
4
|
using Fuby
|
5
5
|
|
6
6
|
module Fuby
|
7
|
-
|
7
|
+
Enumerables.each do |enumerable|
|
8
|
+
next if Hash >= enumerable
|
9
|
+
refine enumerable do
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
alias_method :to_h, :to_hash
|
11
|
+
def to_hash
|
12
|
+
{}.tap { |hash| each_with_index_or_key { |val, key| hash[key] = val } }
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
refine ::Hash do
|
15
|
+
alias_method :to_h, :to_hash
|
17
16
|
|
18
|
-
def to_hash
|
19
|
-
dup
|
20
17
|
end
|
21
|
-
|
22
|
-
alias_method :to_h, :to_hash
|
23
|
-
|
24
18
|
end
|
25
19
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'to_components'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::String do
|
5
|
+
|
6
|
+
def to_SLASH_CASE
|
7
|
+
to_components.join('/').upcase
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_slash_case
|
11
|
+
to_components.join('/').downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
refine ::Symbol do
|
16
|
+
|
17
|
+
def to_SLASH_CASE
|
18
|
+
@to_SLASH_CASE ||= to_s.to_SLASH_CASE.to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_slash_case
|
22
|
+
@to_slash_case ||= to_s.to_slash_case.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/fuby/tok.rb
CHANGED
data/lib/fuby/try_each.rb
CHANGED
data/lib/fuby/try_eval.rb
CHANGED
data/lib/fuby/unshift_options.rb
CHANGED
data/test/fuby/alias_method.rb
CHANGED
@@ -3,7 +3,7 @@ require 'fuby/alias_method'
|
|
3
3
|
using Fuby
|
4
4
|
|
5
5
|
describe Module do
|
6
|
-
describe "alias_method
|
6
|
+
describe "alias_method existing_method_name" do
|
7
7
|
it "creates and returns a new symbol that aliases the existing_method_name" do
|
8
8
|
|
9
9
|
class A
|
@@ -15,7 +15,7 @@ describe Module do
|
|
15
15
|
eval %{
|
16
16
|
|
17
17
|
def foo
|
18
|
-
#{ alias_method
|
18
|
+
#{ alias_method :foo } * 10
|
19
19
|
end
|
20
20
|
|
21
21
|
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fuby/ancestors'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Class do
|
6
|
+
describe "ancestors" do
|
7
|
+
it "returns the same result as `super`" do
|
8
|
+
|
9
|
+
module_A = Module.new
|
10
|
+
class_A = Class.new do include module_A end
|
11
|
+
|
12
|
+
module_B = Module.new
|
13
|
+
class_B = Class.new class_A do include module_B end
|
14
|
+
|
15
|
+
module_C = Module.new
|
16
|
+
class_C = Class.new class_B do include module_C end
|
17
|
+
|
18
|
+
class_C.ancestors.take(6).must_equal [class_C, module_C, class_B, module_B, class_A, module_A]
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
describe "ancestors Type" do
|
23
|
+
it "returns all ancestors of type Type" do
|
24
|
+
|
25
|
+
module_A = Module.new
|
26
|
+
class_A = Class.new do include module_A end
|
27
|
+
|
28
|
+
module_B = Module.new
|
29
|
+
class_B = Class.new class_A do include module_B end
|
30
|
+
|
31
|
+
module_C = Module.new
|
32
|
+
class_C = Class.new class_B do include module_C end
|
33
|
+
|
34
|
+
class_C.ancestors(Class).take(3).must_equal [class_C, class_B, class_A]
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
41
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fuby/cardinality'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Object do
|
6
|
+
describe "cardinality" do
|
7
|
+
it "returns 1 by default" do
|
8
|
+
|
9
|
+
Object.new.cardinality.must_equal 1
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe NilClass do
|
15
|
+
describe "cardinality" do
|
16
|
+
it "returns 0" do
|
17
|
+
|
18
|
+
nil.cardinality.must_equal 0
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe Enumerable do
|
24
|
+
describe "cardinality" do
|
25
|
+
it "returns the size of `self`" do
|
26
|
+
|
27
|
+
{}.cardinality.must_equal 0
|
28
|
+
{ a:1 }.cardinality.must_equal 1
|
29
|
+
[].cardinality.must_equal 0
|
30
|
+
[1, 2, 3].cardinality.must_equal 3
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/fuby/deep.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
data/test/fuby/deep_each.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'fuby/deep_each'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
describe "deep_each" do
|
7
|
+
it "returns an enumerator that yields all leaf elements of `self`" do
|
8
|
+
|
9
|
+
[[1, 2], [3, [4, 5]]].deep_each.to_a.must_equal [[1, 0, 0], [2, 1, 0], [3, 0, 1], [4, 0, 1, 1], [5, 1, 1, 1]]
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
describe "deep_each &block" do
|
14
|
+
it "traverses `self` and all nested instances of `self.class` with the given block" do
|
15
|
+
|
16
|
+
result = []
|
17
|
+
[[1, 2], [3, [4, 5]]].deep_each { |e, *path| result << e }
|
18
|
+
result.must_equal [1, 2, 3, 4, 5]
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/fuby/define.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
data/test/fuby/define_tok.rb
CHANGED
data/test/fuby/descendants.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fuby/descendants'
|
2
|
+
require 'fuby/send'
|
3
|
+
|
4
|
+
using Fuby
|
5
|
+
|
6
|
+
describe Class do
|
7
|
+
describe "descendants" do
|
8
|
+
it "returns all descendants of `self`" do
|
9
|
+
|
10
|
+
class_A = Class.new
|
11
|
+
class_B = Class.new class_A
|
12
|
+
class_C = Class.new class_B
|
13
|
+
class_D = Class.new class_C
|
14
|
+
|
15
|
+
class_A.descendants.must_include class_B
|
16
|
+
class_A.descendants.must_include class_C
|
17
|
+
class_A.descendants.must_include class_D
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
describe Module do
|
23
|
+
describe "descendants" do
|
24
|
+
it "returns all descendants of `self`" do
|
25
|
+
|
26
|
+
module_A = Module.new
|
27
|
+
module_B = Module.new.send.include module_A
|
28
|
+
module_C = Module.new.send.include module_B
|
29
|
+
module_D = Module.new.send.include module_C
|
30
|
+
|
31
|
+
module_A.descendants.must_include module_B
|
32
|
+
module_A.descendants.must_include module_C
|
33
|
+
module_A.descendants.must_include module_D
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "descendants Type" do
|
38
|
+
it "returns all descendants of `self` with type Type" do
|
39
|
+
|
40
|
+
# module AA; end
|
41
|
+
# class A; include AA; end
|
42
|
+
|
43
|
+
# module BB; end
|
44
|
+
# class B < A; include BB; end
|
45
|
+
|
46
|
+
# module CC; end
|
47
|
+
# class C < B: include CC; end
|
48
|
+
|
49
|
+
# C.descendants(Class).take(3).must_equal [C, B, A]
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
56
|
+
Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
|
data/test/fuby/drop_until.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
|
1
|
+
require 'fuby/drop_until'
|
2
2
|
|
3
|
-
|
3
|
+
using Fuby
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe Array do
|
6
|
+
describe "drop_until predicate = Proc.new" do
|
7
|
+
it "returns a new array dropping the initial elements that don't match the given predicate" do
|
8
8
|
|
9
|
-
|
9
|
+
xs = [1, 2, 3, :four]
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
xs.drop_until { false }.must_equal []
|
12
|
+
xs.drop_until(Symbol).must_equal [:four]
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe "drop_until! predicate = Proc.new" do
|
17
|
+
it "dropping the initial elements that don't match the given predicate, returning self" do
|
18
18
|
|
19
|
-
|
19
|
+
xs = [1, 2, 3, :four]
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
xs.drop_until!(Symbol).must_equal xs
|
22
|
+
xs.must_equal [:four]
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/fuby/drop_while.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
|
1
|
+
require 'fuby/drop_while'
|
2
2
|
|
3
|
-
|
3
|
+
using Fuby
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe Array do
|
6
|
+
describe "drop_while predicate = Proc.new" do
|
7
|
+
it "returns a new array dropping the initial elements matching the given predicate" do
|
8
8
|
|
9
|
-
|
9
|
+
xs = [1, 2, 3, :four]
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
xs.drop_while { true }.must_equal []
|
12
|
+
xs.drop_while(Integer).must_equal [:four]
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe "drop_while! predicate = Proc.new" do
|
17
|
+
it "dropping the initial elements matching the given predicate, returning self" do
|
18
18
|
|
19
|
-
|
19
|
+
xs = [1, 2, 3, :four]
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
xs.drop_while!(Integer).must_equal xs
|
22
|
+
xs.must_equal [:four]
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|