mug 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mug/and-or.rb +26 -26
  3. data/lib/mug/any-and-all.rb +16 -16
  4. data/lib/mug/apply.rb +37 -37
  5. data/lib/mug/array/extend.rb +43 -43
  6. data/lib/mug/array/minus.rb +32 -32
  7. data/lib/mug/bool.rb +71 -71
  8. data/lib/mug/clamp.rb +35 -35
  9. data/lib/mug/counts.rb +27 -27
  10. data/lib/mug/fragile-method-chain.rb +42 -42
  11. data/lib/mug/hash/map.rb +75 -75
  12. data/lib/mug/hash/operations.rb +47 -47
  13. data/lib/mug/iterator/for.rb +7 -7
  14. data/lib/mug/iterator/method.rb +7 -7
  15. data/lib/mug/iterator_c.rb +14 -14
  16. data/lib/mug/loop-with.rb +30 -29
  17. data/lib/mug/matchdata/each.rb +40 -40
  18. data/lib/mug/matchdata/hash.rb +29 -29
  19. data/lib/mug/maybe.rb +33 -33
  20. data/lib/mug/negativity.rb +20 -20
  21. data/lib/mug/not.rb +6 -6
  22. data/lib/mug/rexproc.rb +6 -6
  23. data/lib/mug/self.rb +31 -31
  24. data/lib/mug/to_h.rb +2 -2
  25. data/lib/mug/top.rb +100 -100
  26. data/test/test-and-or.rb +32 -32
  27. data/test/test-any-and-all.rb +19 -19
  28. data/test/test-apply.rb +47 -47
  29. data/test/test-array-extend.rb +54 -54
  30. data/test/test-array-minus.rb +11 -11
  31. data/test/test-bool.rb +48 -48
  32. data/test/test-clamp.rb +42 -42
  33. data/test/test-counts.rb +21 -21
  34. data/test/test-fragile-method-chain.rb +56 -56
  35. data/test/test-hashmap.rb +14 -14
  36. data/test/test-hashop.rb +47 -47
  37. data/test/test-iterator-for.rb +12 -12
  38. data/test/test-loop-with.rb +117 -66
  39. data/test/test-matchdata_each.rb +50 -50
  40. data/test/test-matchdata_hash.rb +40 -40
  41. data/test/test-maybe.rb +76 -76
  42. data/test/test-negativity.rb +40 -40
  43. data/test/test-not.rb +53 -53
  44. data/test/test-rexproc.rb +6 -6
  45. data/test/test-self.rb +21 -21
  46. data/test/test-tau.rb +12 -12
  47. data/test/test-top.rb +100 -100
  48. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0edc2446a16fda4757caa14b0fda411f56cd579
4
- data.tar.gz: 7282d21792083c5b6702933c248be85b188bdf4e
3
+ metadata.gz: 4c1c6c199bc0b20f762e2ddc28c8e27d1afef202
4
+ data.tar.gz: fe61f0da462afe3afda46c1e4a7e1efe0567c55c
5
5
  SHA512:
6
- metadata.gz: 6287a2a374fffb41434813eaeeebf7f5e8336e2d9f099fda1d81842ff94fbe0f0b0bae9816dfeb2cedb72e3982a0058237964e8743b6841c1710a43fc75f94f7
7
- data.tar.gz: eaa5258cba1132392718fcfaa5982396d8ef0a646c537c8f383643cd3720fbaa69ecca97adc8e7fa3b53b21152ce86c6d9161169b3ad41090d135d89bb211293
6
+ metadata.gz: 153d565d0327384349577c8860bd65b6535a08df5639f1a0f42b61fee9edb5f3d23ef70821921a64d8492ea6d1c697923214b673f6059d16512e1556e0bfbc8b
7
+ data.tar.gz: 8753cd45eaf6e9e05e6f60678f9c8dce87055de4c9be7b95b1c6a0f2be28d4cb6e93cba67045b5b7958e091c8e36c7650abf411944043e06f1446f57bbb91886
@@ -1,33 +1,33 @@
1
1
 
2
2
  class Object
3
3
 
4
- #
5
- # Returns either +obj+ or +default+, depending on the falsiness of +obj+.
6
- #
7
- # If a block is given, +obj+ is yielded to it; if it returns truthy,
8
- # +default+ is returned, otherwise +obj+ is returned.
9
- #
10
- def and default
11
- if block_given?
12
- yield(self) ? default : self
13
- else
14
- self && default
15
- end
16
- end
4
+ #
5
+ # Returns either +obj+ or +default+, depending on the falsiness of +obj+.
6
+ #
7
+ # If a block is given, +obj+ is yielded to it; if it returns truthy,
8
+ # +default+ is returned, otherwise +obj+ is returned.
9
+ #
10
+ def and default
11
+ if block_given?
12
+ yield(self) ? default : self
13
+ else
14
+ self && default
15
+ end
16
+ end
17
17
 
18
- #
19
- # Returns either +obj+ or +default+, depending on the truthiness of +obj+.
20
- #
21
- # If a block is given, +obj+ is yielded to it; if it returns truthy,
22
- # +obj+ is returned, otherwise +default+ is returned.
23
- #
24
- def or default
25
- if block_given?
26
- yield(self) ? self : default
27
- else
28
- self || default
29
- end
30
- end
18
+ #
19
+ # Returns either +obj+ or +default+, depending on the truthiness of +obj+.
20
+ #
21
+ # If a block is given, +obj+ is yielded to it; if it returns truthy,
22
+ # +obj+ is returned, otherwise +default+ is returned.
23
+ #
24
+ def or default
25
+ if block_given?
26
+ yield(self) ? self : default
27
+ else
28
+ self || default
29
+ end
30
+ end
31
31
  end
32
32
 
33
33
  =begin
@@ -1,22 +1,22 @@
1
1
 
2
2
  module Enumerable
3
3
 
4
- #
5
- # Passes each element of the collection to the given block. The method returns `true` if the
6
- # block contains elements that never return `false` or `nil`. If the block is not given, Ruby
7
- # adds an implicit block of `{ |obj| obj }` which will cause `and_and_all?` to return `true`
8
- # when none of the collection members are `false` or `nil`.
9
- #
10
- def any_and_all? &block
11
- block ||= proc {|obj| obj }
12
-
13
- result = false
14
- each do |x|
15
- return false unless block[x]
16
- result = true
17
- end
18
- result
19
- end
4
+ #
5
+ # Passes each element of the collection to the given block. The method returns `true` if the
6
+ # block contains elements that never return `false` or `nil`. If the block is not given, Ruby
7
+ # adds an implicit block of `{ |obj| obj }` which will cause `and_and_all?` to return `true`
8
+ # when none of the collection members are `false` or `nil`.
9
+ #
10
+ def any_and_all? &block
11
+ block ||= proc {|obj| obj }
12
+
13
+ result = false
14
+ each do |x|
15
+ return false unless block[x]
16
+ result = true
17
+ end
18
+ result
19
+ end
20
20
 
21
21
  end
22
22
 
@@ -1,46 +1,46 @@
1
1
 
2
2
  class Proc
3
- #
4
- # Curries this Proc and partially applies parameters.
5
- # If a sufficient number of arguments are supplied, it passes the
6
- # supplied arguments to the original proc and returns the result.
7
- # Otherwise, returns another curried proc that takes the rest of
8
- # arguments.
9
- #
10
- def apply(*args)
11
- curry.call(*args)
12
- end
3
+ #
4
+ # Curries this Proc and partially applies parameters.
5
+ # If a sufficient number of arguments are supplied, it passes the
6
+ # supplied arguments to the original proc and returns the result.
7
+ # Otherwise, returns another curried proc that takes the rest of
8
+ # arguments.
9
+ #
10
+ def apply(*args)
11
+ curry.call(*args)
12
+ end
13
13
  end
14
14
 
15
15
  class Method
16
- if RUBY_VERSION < '2.2'
17
- #
18
- # Returns a curried proc. If the optional arity argument is given,
19
- # it determines the number of arguments. A curried proc receives
20
- # some arguments. If a sufficient number of arguments are supplied,
21
- # it passes the supplied arguments to the original proc and returns
22
- # the result. Otherwise, returns another curried proc that takes the
23
- # rest of arguments.
24
- #
25
- def curry(n=nil)
26
- if n
27
- to_proc.curry n
28
- else
29
- to_proc.curry
30
- end
31
- end
32
- end
16
+ if RUBY_VERSION < '2.2'
17
+ #
18
+ # Returns a curried proc. If the optional arity argument is given,
19
+ # it determines the number of arguments. A curried proc receives
20
+ # some arguments. If a sufficient number of arguments are supplied,
21
+ # it passes the supplied arguments to the original proc and returns
22
+ # the result. Otherwise, returns another curried proc that takes the
23
+ # rest of arguments.
24
+ #
25
+ def curry(n=nil)
26
+ if n
27
+ to_proc.curry n
28
+ else
29
+ to_proc.curry
30
+ end
31
+ end
32
+ end
33
33
 
34
- #
35
- # Curries this Method and partially applies parameters.
36
- # If a sufficient number of arguments are supplied, it passes the
37
- # supplied arguments to the original proc and returns the result.
38
- # Otherwise, returns another curried proc that takes the rest of
39
- # arguments.
40
- #
41
- def apply(*args)
42
- curry.call(*args)
43
- end
34
+ #
35
+ # Curries this Method and partially applies parameters.
36
+ # If a sufficient number of arguments are supplied, it passes the
37
+ # supplied arguments to the original proc and returns the result.
38
+ # Otherwise, returns another curried proc that takes the rest of
39
+ # arguments.
40
+ #
41
+ def apply(*args)
42
+ curry.call(*args)
43
+ end
44
44
  end
45
45
 
46
46
  =begin
@@ -1,53 +1,53 @@
1
1
 
2
2
  class Array
3
3
 
4
- ##
5
- # Extend this Array.
6
- #
7
- # In the first form, when a +size+ and an optional +obj+ are sent,
8
- # the array is extended with +size+ copies of +obj+. Take notice that
9
- # all elements will reference the same object +obj+.
10
- #
11
- # The second form appends a copy of the array passed as a parameter
12
- # (the array is generated by calling #to_ary on the parameter).
13
- # @see #concat
14
- # @see #+
15
- #
16
- # In the last form, the array is extended by the given size. Each new
17
- # element in the array is created by passing the element's index to the
18
- # given block and storing the return value.
19
- #
20
- # @call-seq extend!(size=0, obj=nil)
21
- # @call-seq extend!(array)
22
- # @call-seq extend!(size) {|index| block }
23
- #
24
- def extend! size, *rest
25
- raise ArgumentError, "wrong number of arguments (#{rest.length+1} for 1..2)" if rest.length > 1
4
+ ##
5
+ # Extend this Array.
6
+ #
7
+ # In the first form, when a +size+ and an optional +obj+ are sent,
8
+ # the array is extended with +size+ copies of +obj+. Take notice that
9
+ # all elements will reference the same object +obj+.
10
+ #
11
+ # The second form appends a copy of the array passed as a parameter
12
+ # (the array is generated by calling #to_ary on the parameter).
13
+ # @see #concat
14
+ # @see #+
15
+ #
16
+ # In the last form, the array is extended by the given size. Each new
17
+ # element in the array is created by passing the element's index to the
18
+ # given block and storing the return value.
19
+ #
20
+ # @call-seq extend!(size=0, obj=nil)
21
+ # @call-seq extend!(array)
22
+ # @call-seq extend!(size) {|index| block }
23
+ #
24
+ def extend! size, *rest
25
+ raise ArgumentError, "wrong number of arguments (#{rest.length+1} for 1..2)" if rest.length > 1
26
26
 
27
- # Same logic as array.c/rb_ary_initialize
28
- if rest.empty? && !size.is_a?(Fixnum)
29
- warn 'warning: given block not used' if block_given?
30
- concat size.to_ary
31
- return self
32
- end
27
+ # Same logic as array.c/rb_ary_initialize
28
+ if rest.empty? && !size.is_a?(Fixnum)
29
+ warn 'warning: given block not used' if block_given?
30
+ concat size.to_ary
31
+ return self
32
+ end
33
33
 
34
- raise ArgumentError, 'negative size' if size < 0
34
+ raise ArgumentError, 'negative size' if size < 0
35
35
 
36
- a = length
37
- b = a+size
38
- if block_given?
39
- warn 'warning: block supersedes default value argument' if !rest.empty?
40
- fill(a...b) {|i| yield i }
41
- else
42
- obj = rest[0]
43
- fill(a...b) { obj }
44
- end
45
- end
36
+ a = length
37
+ b = a+size
38
+ if block_given?
39
+ warn 'warning: block supersedes default value argument' if !rest.empty?
40
+ fill(a...b) {|i| yield i }
41
+ else
42
+ obj = rest[0]
43
+ fill(a...b) { obj }
44
+ end
45
+ end
46
46
 
47
- # @see #extend!
48
- def extend *args, &block
49
- dup.extend!( *args, &block )
50
- end
47
+ # @see #extend!
48
+ def extend *args, &block
49
+ dup.extend!( *args, &block )
50
+ end
51
51
 
52
52
  end
53
53
 
@@ -1,38 +1,38 @@
1
1
 
2
2
  class Array
3
3
 
4
- ##
5
- # Subtract elements from this array.
6
- #
7
- # This is similar to Array#- except that elements from this array are
8
- # removed only once per instance in +ary+.
9
- #
10
- # If +remainder+ is given and true, returns a second array which is
11
- # all elements in +ary+ that were not present in this array.
12
- #
13
- # @call-seq minus(ary)
14
- # @call-seq minus(ary, remainder: true)
15
- #
16
- def minus ary, remainder: false
17
-
18
- result = dup
19
- rem = []
20
-
21
- ary.each do |x|
22
- i = result.index x
23
- if i
24
- result.delete_at i
25
- elsif remainder
26
- rem << x
27
- end
28
- end
29
-
30
- if remainder
31
- [result, rem]
32
- else
33
- result
34
- end
35
- end
4
+ ##
5
+ # Subtract elements from this array.
6
+ #
7
+ # This is similar to Array#- except that elements from this array are
8
+ # removed only once per instance in +ary+.
9
+ #
10
+ # If +remainder+ is given and true, returns a second array which is
11
+ # all elements in +ary+ that were not present in this array.
12
+ #
13
+ # @call-seq minus(ary)
14
+ # @call-seq minus(ary, remainder: true)
15
+ #
16
+ def minus ary, remainder: false
17
+
18
+ result = dup
19
+ rem = []
20
+
21
+ ary.each do |x|
22
+ i = result.index x
23
+ if i
24
+ result.delete_at i
25
+ elsif remainder
26
+ rem << x
27
+ end
28
+ end
29
+
30
+ if remainder
31
+ [result, rem]
32
+ else
33
+ result
34
+ end
35
+ end
36
36
 
37
37
  end
38
38
 
@@ -3,23 +3,23 @@
3
3
  # Converts arg to a boolean (true or false).
4
4
  #
5
5
  def Bool(arg)
6
- !!arg
6
+ !!arg
7
7
  end
8
8
 
9
9
  class Object
10
- #
11
- # Converts obj to a boolean.
12
- #
13
- def to_bool
14
- true
15
- end
16
-
17
- #
18
- # Converts obj to a boolean.
19
- #
20
- def to_b
21
- true
22
- end
10
+ #
11
+ # Converts obj to a boolean.
12
+ #
13
+ def to_bool
14
+ true
15
+ end
16
+
17
+ #
18
+ # Converts obj to a boolean.
19
+ #
20
+ def to_b
21
+ true
22
+ end
23
23
  end
24
24
 
25
25
  def nil.to_bool; false; end
@@ -28,86 +28,86 @@ def false.to_bool; false; end
28
28
  def false.to_b; false; end
29
29
 
30
30
  class Numeric
31
- #
32
- # Converts num to a boolean.
33
- # Returns true if not zero.
34
- #
35
- def to_b
36
- self != 0
37
- end
31
+ #
32
+ # Converts num to a boolean.
33
+ # Returns true if not zero.
34
+ #
35
+ def to_b
36
+ self != 0
37
+ end
38
38
  end
39
39
 
40
40
  class Float
41
- #
42
- # Converts num to a boolean.
43
- # Returns true if not zero or NaN.
44
- # Note: -0.0 is false, and +/-infinity are true.
45
- #
46
- def to_b
47
- !(self.zero? || self.nan?)
48
- end
41
+ #
42
+ # Converts num to a boolean.
43
+ # Returns true if not zero or NaN.
44
+ # Note: -0.0 is false, and +/-infinity are true.
45
+ #
46
+ def to_b
47
+ !(self.zero? || self.nan?)
48
+ end
49
49
  end
50
50
 
51
51
  class String
52
- #
53
- # Converts str to a boolean.
54
- # Returns true if not empty.
55
- #
56
- def to_b
57
- !empty?
58
- end
52
+ #
53
+ # Converts str to a boolean.
54
+ # Returns true if not empty.
55
+ #
56
+ def to_b
57
+ !empty?
58
+ end
59
59
  end
60
60
 
61
61
  class Array
62
- #
63
- # Converts ary to a boolean.
64
- # Returns true if not empty.
65
- #
66
- def to_b
67
- !empty?
68
- end
62
+ #
63
+ # Converts ary to a boolean.
64
+ # Returns true if not empty.
65
+ #
66
+ def to_b
67
+ !empty?
68
+ end
69
69
  end
70
70
 
71
71
  class Hash
72
- #
73
- # Converts hsh to a boolean.
74
- # Returns true if not empty.
75
- #
76
- def to_b
77
- !empty?
78
- end
72
+ #
73
+ # Converts hsh to a boolean.
74
+ # Returns true if not empty.
75
+ #
76
+ def to_b
77
+ !empty?
78
+ end
79
79
  end
80
80
 
81
81
  module Enumerable
82
- #
83
- # Converts enum to a boolean.
84
- # Returns true if there are any elements.
85
- #
86
- def to_b
87
- any?{ true }
88
- end
82
+ #
83
+ # Converts enum to a boolean.
84
+ # Returns true if there are any elements.
85
+ #
86
+ def to_b
87
+ any?{ true }
88
+ end
89
89
  end
90
90
 
91
91
  if RUBY_VERSION.to_i >= 2
92
92
  class Enumerator
93
- #
94
- # Converts enum to a boolean.
95
- # Returns true if there are any elements.
96
- #
97
- def to_b
98
- size.to_b
99
- end
93
+ #
94
+ # Converts enum to a boolean.
95
+ # Returns true if there are any elements.
96
+ #
97
+ def to_b
98
+ size.to_b
99
+ end
100
100
  end
101
101
  end
102
102
 
103
103
  class Exception
104
- #
105
- # Converts ex to a boolean.
106
- # All Exceptions are considered false.
107
- #
108
- def to_b
109
- false
110
- end
104
+ #
105
+ # Converts ex to a boolean.
106
+ # All Exceptions are considered false.
107
+ #
108
+ def to_b
109
+ false
110
+ end
111
111
  end
112
112
 
113
113
  =begin