fuby 0.0.2 → 0.0.3

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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/fuby.gemspec +1 -1
  5. data/lib/fuby/alias_method.rb +26 -2
  6. data/lib/fuby/alias_singleton_method.rb +20 -0
  7. data/lib/fuby/ancestors.rb +12 -0
  8. data/lib/fuby/cardinality.rb +27 -0
  9. data/lib/fuby/curry_eval.rb +19 -0
  10. data/lib/fuby/deep_const_get.rb +13 -0
  11. data/lib/fuby/deep_each.rb +21 -6
  12. data/lib/fuby/define.rb +1 -0
  13. data/lib/fuby/define_missing_method.rb +13 -23
  14. data/lib/fuby/define_tok.rb +2 -0
  15. data/lib/fuby/descendants.rb +3 -4
  16. data/lib/fuby/eastern_name.rb +11 -0
  17. data/lib/fuby/enumerables.rb +7 -0
  18. data/lib/fuby/eql_componentwise.rb +7 -4
  19. data/lib/fuby/equivalence.rb +7 -4
  20. data/lib/fuby/eval.rb +1 -51
  21. data/lib/fuby/extend.rb +15 -4
  22. data/lib/fuby/first.rb +9 -0
  23. data/lib/fuby/hash_eval.rb +32 -0
  24. data/lib/fuby/include.rb +14 -3
  25. data/lib/fuby/invert.rb +10 -7
  26. data/lib/fuby/last.rb +9 -0
  27. data/lib/fuby/longest_common.rb +1 -15
  28. data/lib/fuby/longest_common_prefix.rb +11 -0
  29. data/lib/fuby/longest_common_suffix.rb +11 -0
  30. data/lib/fuby/matches.rb +12 -4
  31. data/lib/fuby/matches_componentwise.rb +11 -4
  32. data/lib/fuby/matches_part_of.rb +9 -5
  33. data/lib/fuby/matches_prefix_of.rb +6 -1
  34. data/lib/fuby/matches_suffix_of.rb +3 -0
  35. data/lib/fuby/method_added_as_binary_operator.rb +3 -1
  36. data/lib/fuby/method_added_as_filter.rb +1 -1
  37. data/lib/fuby/names.rb +9 -0
  38. data/lib/fuby/outer_module.rb +18 -0
  39. data/lib/fuby/part_of.rb +4 -0
  40. data/lib/fuby/pop.rb +3 -2
  41. data/lib/fuby/prefix_of.rb +5 -4
  42. data/lib/fuby/prepend.rb +12 -3
  43. data/lib/fuby/reject.rb +19 -0
  44. data/lib/fuby/select.rb +19 -0
  45. data/lib/fuby/self_and_descendants.rb +1 -3
  46. data/lib/fuby/send.rb +24 -0
  47. data/lib/fuby/shift.rb +3 -2
  48. data/lib/fuby/singleton_method_defined.rb +9 -0
  49. data/lib/fuby/subclass.rb +2 -2
  50. data/lib/fuby/submodule.rb +2 -2
  51. data/lib/fuby/suffix_of.rb +2 -6
  52. data/lib/fuby/take_until.rb +5 -0
  53. data/lib/fuby/take_while.rb +8 -0
  54. data/lib/fuby/to_camel_case.rb +1 -1
  55. data/lib/fuby/to_dot_case.rb +26 -0
  56. data/lib/fuby/to_hash.rb +8 -14
  57. data/lib/fuby/to_slash_case.rb +26 -0
  58. data/lib/fuby/tok.rb +0 -1
  59. data/lib/fuby/try_each.rb +1 -0
  60. data/lib/fuby/try_eval.rb +1 -0
  61. data/lib/fuby/unshift_options.rb +1 -0
  62. data/lib/fuby/western_name.rb +11 -0
  63. data/test/fuby/alias_method.rb +2 -2
  64. data/test/fuby/ancestors.rb +41 -0
  65. data/test/fuby/cardinality.rb +34 -0
  66. data/test/fuby/curry_eval.rb +3 -0
  67. data/test/fuby/deep.rb +1 -0
  68. data/test/fuby/deep_each.rb +22 -0
  69. data/test/fuby/define.rb +1 -0
  70. data/test/fuby/define_tok.rb +3 -0
  71. data/test/fuby/descendants.rb +56 -0
  72. data/test/fuby/drop_until.rb +18 -18
  73. data/test/fuby/drop_while.rb +18 -18
  74. data/test/fuby/each.rb +1 -0
  75. data/test/fuby/eql.rb +1 -0
  76. data/test/fuby/eql_componentwise.rb +4 -0
  77. data/test/fuby/equivalence.rb +14 -0
  78. data/test/fuby/eval.rb +1 -0
  79. data/test/fuby/extend.rb +1 -1
  80. data/test/fuby/format.rb +3 -0
  81. data/test/fuby/hash_eval.rb +3 -0
  82. data/test/fuby/include.rb +1 -1
  83. data/test/fuby/index_or_key.rb +3 -0
  84. data/test/fuby/invert.rb +22 -0
  85. data/test/fuby/longest_common.rb +1 -0
  86. data/test/fuby/longest_common_prefix.rb +3 -0
  87. data/test/fuby/longest_common_suffix.rb +3 -0
  88. data/test/fuby/matches.rb +5 -0
  89. data/test/fuby/matches_part_of.rb +3 -0
  90. data/test/fuby/matches_prefix_of.rb +3 -0
  91. data/test/fuby/matches_suffix_of.rb +3 -0
  92. data/test/fuby/new.rb +19 -0
  93. data/test/fuby/part_of.rb +5 -0
  94. data/test/fuby/prefix_of.rb +5 -0
  95. data/test/fuby/prepend.rb +1 -1
  96. data/test/fuby/private.rb +3 -0
  97. data/test/fuby/protected.rb +3 -0
  98. data/test/fuby/public.rb +3 -0
  99. data/test/fuby/push.rb +1 -0
  100. data/test/fuby/random.rb +3 -0
  101. data/test/fuby/self_and_descendants.rb +3 -0
  102. data/test/fuby/shift.rb +5 -0
  103. data/test/fuby/shift_if.rb +3 -0
  104. data/test/fuby/shift_options.rb +3 -0
  105. data/test/fuby/shift_unless.rb +3 -0
  106. data/test/fuby/shift_until.rb +3 -0
  107. data/test/fuby/shift_while.rb +3 -0
  108. data/test/fuby/splat.rb +3 -0
  109. data/test/fuby/strip.rb +3 -0
  110. data/test/fuby/suffix_of.rb +5 -0
  111. data/test/fuby/take.rb +5 -0
  112. data/test/fuby/take_until.rb +3 -0
  113. data/test/fuby/take_while.rb +3 -0
  114. data/test/fuby/to_components.rb +3 -0
  115. data/test/fuby/to_dot_case.rb +15 -0
  116. data/test/fuby/to_slash_case.rb +15 -0
  117. data/test/fuby/to_tok.rb +3 -0
  118. data/test/fuby/tok.rb +1 -0
  119. data/test/fuby/tok_arity.rb +3 -0
  120. data/test/fuby/tok_direction.rb +3 -0
  121. data/test/fuby/tok_parity.rb +3 -0
  122. data/test/fuby/tok_side.rb +3 -0
  123. data/test/fuby/try.rb +52 -52
  124. data/test/fuby/try_each.rb +1 -1
  125. data/test/fuby/try_eval.rb +2 -2
  126. data/test/fuby/unshift.rb +3 -0
  127. data/test/fuby/unshift_options.rb +3 -0
  128. metadata +50 -24
  129. data/lib/fuby/attributes.rb +0 -15
  130. data/lib/fuby/class_attributes.rb +0 -37
  131. data/lib/fuby/dimension.rb +0 -23
  132. data/lib/fuby/instance_attributes.rb +0 -37
  133. data/lib/fuby/try_exec.rb +0 -16
  134. data/test/fuby/attributes.rb +0 -0
  135. data/test/fuby/class_attributes.rb +0 -0
  136. data/test/fuby/dimension.rb +0 -0
  137. data/test/fuby/instance_attributes.rb +0 -0
  138. data/test/fuby/try_exec.rb +0 -0
@@ -5,13 +5,9 @@ module Fuby
5
5
  eql? that.drop -length
6
6
  end
7
7
 
8
- def matches_suffix_of? that
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 "*_suffix_of.rb", &method(:require)
13
+ Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
@@ -1,3 +1,8 @@
1
+ require_relative 'method_added_as_filter'
2
+ require_relative 'not'
3
+
4
+ using Fuby
5
+
1
6
  module Fuby
2
7
  refine ::Array do
3
8
 
@@ -1,6 +1,14 @@
1
+ require_relative 'method_added_as_filter'
2
+
3
+ using Fuby
4
+
1
5
  module Fuby
2
6
  refine ::Array do
3
7
 
8
+ def take_while
9
+ super
10
+ end
11
+
4
12
  def take_while! &blk
5
13
  pop length - index(&blk)
6
14
  self
@@ -12,7 +12,7 @@ module Fuby
12
12
  end
13
13
 
14
14
  def to_CamelCase
15
- to_components.map! { |str| str.sub /[A-z0-9]/, &:upcase }.join
15
+ to_components.map { |str| str.sub /[A-z0-9]/, &:upcase }.join
16
16
  end
17
17
 
18
18
  end
@@ -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
@@ -1,25 +1,19 @@
1
- require_relative 'descendants'
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
- module ::Enumerable # can't refine a Module
7
+ Enumerables.each do |enumerable|
8
+ next if Hash >= enumerable
9
+ refine enumerable do
8
10
 
9
- def to_hash
10
- {}.tap { |hash| each_with_index_or_key { |val, key| hash[key] = val } }
11
- end
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
- end
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
@@ -1,2 +1 @@
1
1
  Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
2
-
@@ -1,4 +1,5 @@
1
1
  require_relative 'try'
2
+
2
3
  using Fuby
3
4
 
4
5
  module Fuby
@@ -1,4 +1,5 @@
1
1
  require_relative 'try'
2
+
2
3
  using Fuby
3
4
 
4
5
  module Fuby
@@ -1,4 +1,5 @@
1
1
  require_relative 'shift_options'
2
+
2
3
  using Fuby
3
4
 
4
5
  module Fuby
@@ -0,0 +1,11 @@
1
+ require_relative 'names'
2
+
3
+ module Fuby
4
+ refine ::Module do
5
+
6
+ def western_name
7
+ names.reverse.join ' '
8
+ end
9
+
10
+ end
11
+ end
@@ -3,7 +3,7 @@ require 'fuby/alias_method'
3
3
  using Fuby
4
4
 
5
5
  describe Module do
6
- describe "alias_method! existing_method_name" do
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! :foo } * 10
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
@@ -0,0 +1,3 @@
1
+ require 'fuby/curry_eval'
2
+
3
+ using Fuby
@@ -0,0 +1 @@
1
+ Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
@@ -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
@@ -0,0 +1 @@
1
+ Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
@@ -0,0 +1,3 @@
1
+ require 'fuby/to_tok'
2
+
3
+ using Fuby
@@ -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)
@@ -1,26 +1,26 @@
1
- # require 'fuby/drop_until'
1
+ require 'fuby/drop_until'
2
2
 
3
- # using Fuby
3
+ using Fuby
4
4
 
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
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
- # xs = [1, 2, 3, :four]
9
+ xs = [1, 2, 3, :four]
10
10
 
11
- # xs.drop_until { false }.must_equal []
12
- # xs.drop_until(Symbol).must_equal [:four]
11
+ xs.drop_until { false }.must_equal []
12
+ xs.drop_until(Symbol).must_equal [:four]
13
13
 
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
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
- # xs = [1, 2, 3, :four]
19
+ xs = [1, 2, 3, :four]
20
20
 
21
- # xs.drop_until!(Symbol).must_equal xs
22
- # xs.must_equal [:four]
21
+ xs.drop_until!(Symbol).must_equal xs
22
+ xs.must_equal [:four]
23
23
 
24
- # end
25
- # end
26
- # end
24
+ end
25
+ end
26
+ end
@@ -1,26 +1,26 @@
1
- # require 'fuby/drop_while'
1
+ require 'fuby/drop_while'
2
2
 
3
- # using Fuby
3
+ using Fuby
4
4
 
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
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
- # xs = [1, 2, 3, :four]
9
+ xs = [1, 2, 3, :four]
10
10
 
11
- # xs.drop_while { true }.must_equal []
12
- # xs.drop_while(Integer).must_equal [:four]
11
+ xs.drop_while { true }.must_equal []
12
+ xs.drop_while(Integer).must_equal [:four]
13
13
 
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
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
- # xs = [1, 2, 3, :four]
19
+ xs = [1, 2, 3, :four]
20
20
 
21
- # xs.drop_while!(Integer).must_equal xs
22
- # xs.must_equal [:four]
21
+ xs.drop_while!(Integer).must_equal xs
22
+ xs.must_equal [:four]
23
23
 
24
- # end
25
- # end
26
- # end
24
+ end
25
+ end
26
+ end