fuby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,11 +1,22 @@
1
+ require_relative 'send'
2
+
1
3
  module Fuby
2
4
  refine ::Module do
3
5
 
4
- def include! *includes, &body
5
- include *includes unless includes.empty?
6
- include ::Module.new(&body) if block_given?
6
+ def include *includes, &body
7
+ self.send :include, *includes unless includes.empty?
8
+ self.send :include, ::Module.new(&body) if block_given?
7
9
  self
8
10
  end
9
11
 
10
12
  end
13
+ class Send
14
+
15
+ def include *includes, &body
16
+ @self.send :include, *includes unless includes.empty?
17
+ @self.send :include, ::Module.new(&body) if block_given?
18
+ @self
19
+ end
20
+
21
+ end
11
22
  end
@@ -1,14 +1,17 @@
1
- require_relative 'self_and_descendants'
2
- require_relative 'each_with_index_or_key'
1
+ require_relative 'enumerables'
2
+ require_relative 'to_hash'
3
+
4
+ using Fuby
3
5
 
4
6
  module Fuby
7
+ Enumerables.each do |enumerable|
8
+ next if Hash >= enumerable
9
+ refine enumerable do
5
10
 
6
- module ::Enumerable # can't refine Module
11
+ def invert
12
+ to_hash.invert
13
+ end
7
14
 
8
- def invert
9
- ::Hash[ each_with_index_or_key.to_a ]
10
15
  end
11
-
12
16
  end
13
-
14
17
  end
@@ -0,0 +1,9 @@
1
+ module Fuby
2
+ refine ::Array do
3
+
4
+ def last= it
5
+ self[length - 1] = it
6
+ end
7
+
8
+ end
9
+ end
@@ -1,15 +1 @@
1
- require_relative 'equivalence'
2
-
3
- module Fuby
4
- module ::Enumerable # can't refine Module
5
-
6
- def longest_common_prefix *those
7
- zip(*those).take_while(:equivalence?).map(:first)
8
- end
9
-
10
- def longest_common_suffix *those
11
- zip(*those).map(&:reverse).take_while(:equivalence?).map(:first).map(&:reverse)
12
- end
13
-
14
- end
15
- end
1
+ Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
@@ -0,0 +1,11 @@
1
+ require_relative 'equivalence'
2
+
3
+ module Fuby
4
+ refine ::Array do
5
+
6
+ def longest_common_prefix *those
7
+ zip(*those).take_while(:equivalence?).map(:first)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'equivalence'
2
+
3
+ module Fuby
4
+ refine ::Array do
5
+
6
+ def longest_common_suffix *those
7
+ zip(*those).map(&:reverse).take_while(:equivalence?).map(:first).map(&:reverse)
8
+ end
9
+
10
+ end
11
+ end
@@ -1,10 +1,18 @@
1
+ require_relative 'method_added_as_binary_operator'
2
+
3
+ using Fuby
4
+
1
5
  module Fuby
2
- module ::Enumerable # can't refine Module
6
+ Enumerables.each do |enumerable|
7
+ refine enumerable do
3
8
 
4
- def matches? that
5
- count == that.count and matches_componentwise? that
6
- end
9
+ def matches? that
10
+ count == that.count and matches_componentwise? that
11
+ end
7
12
 
13
+ method_added_as_binary_operator :matches?
14
+
15
+ end
8
16
  end
9
17
  end
10
18
 
@@ -1,11 +1,18 @@
1
+ require_relative 'method_added_as_binary_operator'
1
2
  require_relative 'each_with_index_or_key'
2
3
 
4
+ using Fuby
5
+
3
6
  module Fuby
4
- module ::Enumerable # can't refine Module
7
+ Enumerables.each do |enumerable|
8
+ refine enumerable do
5
9
 
6
- def matches_componentwise? that
7
- each_with_index_or_key.all? { |e, k| e === that[k] }
8
- end
10
+ def matches_componentwise? that
11
+ each_with_index_or_key.all? { |e, k| e === that[k] }
12
+ end
9
13
 
14
+ method_added_as_binary_operator :matches_componentwise?
15
+
16
+ end
10
17
  end
11
18
  end
@@ -1,14 +1,18 @@
1
1
  require_relative 'method_added_as_binary_operator'
2
2
  require_relative 'matches_componentwise'
3
3
 
4
+ using Fuby
5
+
4
6
  module Fuby
5
- module ::Enumerable # can't refine Module
7
+ Enumerables.each do |enumerable|
8
+ refine enumerable do
6
9
 
7
- def matches_part_of? that
8
- count <= that.count and matches_componentwise? that
9
- end
10
+ def matches_part_of? that
11
+ count <= that.count and matches_componentwise? that
12
+ end
10
13
 
11
- method_added_as_binary_operator :matches_part_of?
14
+ method_added_as_binary_operator :matches_part_of?
12
15
 
16
+ end
13
17
  end
14
18
  end
@@ -1,9 +1,14 @@
1
+ require_relative 'method_added_as_binary_operator'
1
2
  require_relative 'matches_part_of'
2
3
 
4
+ using Fuby
5
+
3
6
  module Fuby
4
7
  refine ::Array do
5
8
 
6
- alias_method :matches_prefix_of?, :matches_part_of?
9
+ def matches_prefix_of? *sig, &blk
10
+ matches_part_of? *sig, &blk
11
+ end
7
12
 
8
13
  method_added_as_binary_operator :matches_prefix_of?
9
14
 
@@ -1,3 +1,6 @@
1
+ require_relative 'method_added_as_binary_operator'
2
+ require_relative 'matches'
3
+
1
4
  module Fuby
2
5
  refine ::Array do
3
6
 
@@ -1,9 +1,11 @@
1
+ require_relative 'prepend'
2
+
1
3
  module Fuby
2
4
  refine ::Module do
3
5
 
4
6
  def method_added_as_binary_operator *names
5
7
  names.each do |name|
6
- prepend! do
8
+ prepend do
7
9
  define_method name do |*sig|
8
10
  return method name if sig.empty?
9
11
  return super *sig
@@ -6,7 +6,7 @@ module Fuby
6
6
 
7
7
  def method_added_as_filter *names
8
8
  names.each do |name|
9
- prepend! do
9
+ prepend do
10
10
  define_method name do |match = nil, &pred|
11
11
  return method name if match.nil? && pred.nil?
12
12
  return super &(pred || match.to_pred)
@@ -0,0 +1,9 @@
1
+ module Fuby
2
+ refine ::Module do
3
+
4
+ def names
5
+ name.split '::'
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'deep_const_get'
2
+
3
+ module Fuby
4
+ refine ::Module do
5
+
6
+ def outer_module
7
+ @outer_module ||= /::[^:]+\Z/ === self ? Kernel.deep_const_get($`) : Kernel
8
+ end
9
+
10
+ end
11
+ refine ::Kernel.singleton_class do
12
+
13
+ def outer_module
14
+ nil
15
+ end
16
+
17
+ end
18
+ end
@@ -1,6 +1,8 @@
1
1
  require_relative 'method_added_as_binary_operator'
2
2
  require_relative 'eql_componentwise'
3
3
 
4
+ using Fuby
5
+
4
6
  module Fuby
5
7
  module ::Enumerable # can't refine Module
6
8
 
@@ -12,3 +14,5 @@ module Fuby
12
14
 
13
15
  end
14
16
  end
17
+
18
+ Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
@@ -1,8 +1,9 @@
1
1
  module Fuby
2
2
  refine ::Array do
3
3
 
4
- def pop i = 1
5
- return super i % length unless empty?
4
+ def pop i = nil
5
+ return super() unless i
6
+ return super(i % length) unless empty?
6
7
  end
7
8
 
8
9
  end
@@ -3,12 +3,13 @@ require_relative 'part_of'
3
3
  module Fuby
4
4
  refine ::Array do
5
5
 
6
- alias_method :prefix_of?, :part_of?
7
- alias_method :matches_prefix_of?, :matches_part_of?
6
+ def prefix_of? *sig, &blk
7
+ part_of? *sig, &blk
8
+ end
8
9
 
9
- method_added_as_binary_operator :prefix_of?, :matches_prefix_of?
10
+ method_added_as_binary_operator :prefix_of?
10
11
 
11
12
  end
12
13
  end
13
14
 
14
- Dir.glob "*_prefix_of.rb", &method(:require)
15
+ Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
@@ -1,11 +1,20 @@
1
1
  module Fuby
2
2
  refine ::Module do
3
3
 
4
- def prepend! *includes, &body
5
- prepend *includes unless includes.empty?
6
- prepend ::Module.new(&body) if block_given?
4
+ def prepend *includes, &body
5
+ self.send :prepend, *includes unless includes.empty?
6
+ self.send :prepend, ::Module.new(&body) if block_given?
7
7
  self
8
8
  end
9
9
 
10
10
  end
11
+ class Send
12
+
13
+ def prepend *includes, &body
14
+ @self.send :prepend, *includes unless includes.empty?
15
+ @self.send :prepend, ::Module.new(&body) if block_given?
16
+ @self
17
+ end
18
+
19
+ end
11
20
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'method_added_as_filter'
2
+
3
+ using Fuby
4
+
5
+ module Fuby
6
+ refine ::Array do
7
+
8
+ def reject
9
+ super
10
+ end
11
+
12
+ def reject!
13
+ super
14
+ end
15
+
16
+ method_added_as_filter :reject, :reject!
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'method_added_as_filter'
2
+
3
+ using Fuby
4
+
5
+ module Fuby
6
+ refine ::Array do
7
+
8
+ def select
9
+ super
10
+ end
11
+
12
+ def select!
13
+ super
14
+ end
15
+
16
+ method_added_as_filter :select, :select!
17
+
18
+ end
19
+ end
@@ -4,9 +4,7 @@ module Fuby
4
4
  refine ::Module do
5
5
 
6
6
  def self_and_descendants type = ::Module
7
- them = descendants type
8
- them << self if type === self
9
- them
7
+ ObjectSpace.each_object(type).select { |mod| mod <= self }
10
8
  end
11
9
 
12
10
  end
@@ -0,0 +1,24 @@
1
+ module Fuby
2
+ refine ::Object do
3
+
4
+ def send *sig, &blk
5
+ return super unless sig.empty?
6
+ return yield Send.new self if block_given?
7
+ return Send.new self
8
+ end
9
+
10
+ end
11
+ class Send
12
+
13
+ def initialize receiver
14
+ @self = receiver
15
+ end
16
+
17
+ def method_missing key, *sig, &blk
18
+ @self.send key, *sig, &blk
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+ Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
@@ -1,8 +1,9 @@
1
1
  module Fuby
2
2
  refine ::Array do
3
3
 
4
- def shift i = 1
5
- return super i % length unless empty?
4
+ def shift i = nil
5
+ return super() unless i
6
+ return super(i % length) unless empty?
6
7
  end
7
8
 
8
9
  end
@@ -0,0 +1,9 @@
1
+ module Fuby
2
+ refine ::Module do
3
+
4
+ def singleton_method_defined? name
5
+ singleton_class.send :method_defined?, name
6
+ end
7
+
8
+ end
9
+ end
@@ -10,10 +10,10 @@ module Fuby
10
10
  Class.new self
11
11
 
12
12
  when Module
13
- Class.new.include! self
13
+ Class.new.send.include self
14
14
 
15
15
  else super
16
- end.include! *sig, &blk
16
+ end.send.include *sig, &blk
17
17
  end
18
18
 
19
19
  end
@@ -10,10 +10,10 @@ module Fuby
10
10
  Class.new self
11
11
 
12
12
  when Module
13
- Module.new.include! self
13
+ Module.new.send.include self
14
14
 
15
15
  else super
16
- end.include! *sig, &blk
16
+ end.send.include *sig, &blk
17
17
  end
18
18
 
19
19
  end