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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99e1db273fc106282f8517b589af92d19e2360ae
4
- data.tar.gz: 11e5281463debc8412bf2890e433a21b4c4c4ca0
3
+ metadata.gz: c58761ffc821d904ee1c2daff32e6fa90b41391d
4
+ data.tar.gz: c5ed1e2783e92b839030973886f7f84e3ef56101
5
5
  SHA512:
6
- metadata.gz: c6b0d1dc5b4cbe786685f395b4af46898a118a4184b622f42d8f842159adebbaae838f6177724a63cfe4fc71379629836fa8251c9a26ad0638f716615adac567
7
- data.tar.gz: 1a0e4aaff0ddd9e05f6422db698b3ddba4ef3d554b286a275b0765cf66eb98086f690ad820f1f99490f900c10ccaca2ffec15124ad0aa228f8f7fe1aa52ca282
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.2
1
+ 0.0.3
@@ -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.k.goldsmith@gmail.com"]
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"
@@ -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! old_name
7
- Symbol.__uuid__.tap { |new_name| alias_method new_name, old_name }
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
@@ -0,0 +1,13 @@
1
+ module Fuby
2
+ refine ::Module do
3
+
4
+ def deep_const_get *names
5
+ if 1 == names.length
6
+ name = names.first
7
+ names = name.scan /[^:]+/ if /[:]+/ === name
8
+ end
9
+ names.inject(self) { |mod, name| mod.const_get name }
10
+ end
11
+
12
+ end
13
+ end
@@ -1,12 +1,27 @@
1
+ require_relative 'each_with_index_or_key'
2
+ require_relative 'enumerables'
3
+
1
4
  module Fuby
2
- module ::Enumerable # can't refine Module
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
- def deep_each *path, &blk
5
- each_with_index_or_key do |e, i|
6
- return e.deep_each i, *path, &blk if self.class === e
7
- return yield e, *path
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
@@ -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
- alias_method was_method_missing = Symbol.__uuid__, :method_missing
13
-
14
- define_method :method_missing do |key, *sig, &blk|
15
- return send was_method_missing, key, *sig, &blk unless matched_sig = missing_reg.match(key)
16
-
17
- matched_sig = matched_sig.to_a.drop 1
18
-
19
- mod.send :define_method, key do |*sig, &blk|
20
- send missing_method, *(matched_sig + sig), &blk
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
@@ -1,3 +1,5 @@
1
+ require_relative 'to_tok'
2
+
1
3
  module Fuby
2
4
  refine ::Module do
3
5
 
@@ -2,12 +2,11 @@ module Fuby
2
2
  refine ::Module do
3
3
 
4
4
  def descendants type = ::Module
5
- # ObjectSpace.each_object(type).select { |mod| mod < self } FIXME
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 "descendants_*.rb", &method(:require)
13
- Dir.glob "*_descendants.rb", &method(:require)
11
+ Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
12
+ Dir.glob "*_#{ __FILE__.chomp ".rb" }.rb", &method(:require)
@@ -0,0 +1,11 @@
1
+ require_relative 'names'
2
+
3
+ module Fuby
4
+ refine ::Module do
5
+
6
+ def eastern_name
7
+ names.join ' '
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'descendants'
2
+
3
+ using Fuby
4
+
5
+ module Fuby
6
+ Enumerables = ::Enumerable.descendants(Class)
7
+ end
@@ -1,11 +1,14 @@
1
1
  require_relative 'each_with_index_or_key'
2
+ require_relative 'enumerables'
2
3
 
3
4
  module Fuby
4
- module ::Enumerable # can't refine Module
5
+ Enumerables.each do |enumerable|
6
+ refine enumerable do
5
7
 
6
- def eql_componentwise? that
7
- each_with_index_or_key.all? { |e, k| e == that[k] }
8
- end
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
@@ -1,11 +1,14 @@
1
1
  require_relative 'splat'
2
+ require_relative 'enumerables'
2
3
 
3
4
  module Fuby
4
- module ::Enumerable # can't refine Module
5
+ Enumerables.each do |enumerable|
6
+ refine enumerable do
5
7
 
6
- def equivalence? eq = :eql?
7
- each_cons(2).splat.all? { |fst, snd| fst.send eq, snd }
8
- end
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
@@ -1,51 +1 @@
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
- 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)
@@ -1,11 +1,22 @@
1
+ require_relative 'send'
2
+
1
3
  module Fuby
2
- refine ::Object do
4
+ refine ::Module do
3
5
 
4
- def extend! *extends, &body
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
@@ -0,0 +1,9 @@
1
+ module Fuby
2
+ refine ::Array do
3
+
4
+ def first= it
5
+ self[0] = it
6
+ end
7
+
8
+ end
9
+ end
@@ -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