mug 1.6.0 → 2.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb47a83a5fb85778ecfb6ad294b1ccd86711c5c62047881ce4851c5fe8a2c7f9
4
- data.tar.gz: ff2b7714c8285e757facbe0f02f95e52aaca8f44a9f5b6b062b0efaeb8937ada
3
+ metadata.gz: 036ea8685c77415a45fcc3403839d6aac7c10143ab56a69a362ae66c810aa783
4
+ data.tar.gz: b7bd3023df0304c0b14e9d8339b04a6822ffd4ad082a2793c9c51a52025c1e6d
5
5
  SHA512:
6
- metadata.gz: 074d7c49a03c63b511e106e557f9c25f4a49b74a670d36775bb9332036199cf49d8af169fe21a2e23fe87ca4454934d4cc2cba4b5a104d726def4854c913b162
7
- data.tar.gz: 9aca8c3fe9266d1333c8e18ef8a4eb054031a4830e1e9f2ccf736009468cf29c9721abfd490504063dcca33eb6895354688bc84c22db214256e8eae88a37c569
6
+ metadata.gz: 627990b12891667c1f062c50f6c8e0807481c5ebc9ab0c0771d61ba639ffb20ddd3118664079ec08ba504c960a06d774c401fc5d50c46fa51bfe54339d512af2
7
+ data.tar.gz: '09e2e5a7068f1d4e4ff43fab783b387d0b1c8d02871e4b7ba9d5a161fee55f543d261ee837c1c23122f66bd179e885608aefe85131d7c0b52cd14a4c6ebe3a40'
data/lib/mug/apply.rb CHANGED
@@ -8,29 +8,12 @@ class Proc
8
8
  # arguments.
9
9
  #
10
10
  def apply(*args)
11
- curry.call(*args)
11
+ n = arity < 0 ? -arity - 1 : arity
12
+ curry(n).call(*args)
12
13
  end
13
14
  end
14
15
 
15
16
  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
33
-
34
17
  #
35
18
  # Curries this Method and partially applies parameters.
36
19
  # If a sufficient number of arguments are supplied, it passes the
@@ -39,12 +22,13 @@ class Method
39
22
  # arguments.
40
23
  #
41
24
  def apply(*args)
42
- curry.call(*args)
25
+ n = arity < 0 ? -arity - 1 : arity
26
+ curry(n).call(*args)
43
27
  end
44
28
  end
45
29
 
46
30
  =begin
47
- Copyright (c) 2014, Matthew Kerwin <matthew@kerwin.net.au>
31
+ Copyright (c) 2014-2026, Matthew Kerwin <matthew@kerwin.net.au>
48
32
 
49
33
  Permission to use, copy, modify, and/or distribute this software for any
50
34
  purpose with or without fee is hereby granted, provided that the above
@@ -45,14 +45,14 @@ class Array
45
45
  end
46
46
 
47
47
  # @see #extend!
48
- def extend *args, &block
49
- dup.extend!(*args, &block)
48
+ def extend(...)
49
+ dup.extend!(...)
50
50
  end
51
51
 
52
52
  end
53
53
 
54
54
  =begin
55
- Copyright (c) 2014-17, Matthew Kerwin <matthew@kerwin.net.au>
55
+ Copyright (c) 2014-2026, Matthew Kerwin <matthew@kerwin.net.au>
56
56
 
57
57
  Permission to use, copy, modify, and/or distribute this software for any
58
58
  purpose with or without fee is hereby granted, provided that the above
data/lib/mug/bool.rb CHANGED
@@ -88,7 +88,6 @@ module Enumerable
88
88
  end
89
89
  end
90
90
 
91
- if RUBY_VERSION.to_i >= 2
92
91
  class Enumerator
93
92
  #
94
93
  # Converts enum to a boolean.
@@ -99,7 +98,6 @@ class Enumerator
99
98
  (s = size).nil? || s.to_b
100
99
  end
101
100
  end
102
- end
103
101
 
104
102
  class Exception
105
103
  #
@@ -112,7 +110,7 @@ class Exception
112
110
  end
113
111
 
114
112
  =begin
115
- Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
113
+ Copyright (c) 2018-2026, Matthew Kerwin <matthew@kerwin.net.au>
116
114
 
117
115
  Permission to use, copy, modify, and/or distribute this software for any
118
116
  purpose with or without fee is hereby granted, provided that the above
data/lib/mug/clamp.rb CHANGED
@@ -1,22 +1,4 @@
1
1
 
2
- class Numeric
3
-
4
- #
5
- # Clamps num so that lower <= new_num <= higher.
6
- #
7
- # Returns lower when num < lower, higher when num > higher, otherwise
8
- # num itself.
9
- #
10
- # Raises an exception if lower > higher
11
- #
12
- def clamp lower, higher=nil
13
- return lower.bound(self) if lower.is_a?(Range) && higher.nil?
14
- raise ArgumentError, 'range must not be negative' if lower > higher
15
- [[lower, self].max, higher].min
16
- end
17
-
18
- end
19
-
20
2
  class Range
21
3
 
22
4
  #
@@ -43,7 +25,7 @@ class Range
43
25
  end
44
26
 
45
27
  =begin
46
- Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
28
+ Copyright (c) 2018-2026, Matthew Kerwin <matthew@kerwin.net.au>
47
29
 
48
30
  Permission to use, copy, modify, and/or distribute this software for any
49
31
  purpose with or without fee is hereby granted, provided that the above
@@ -14,27 +14,10 @@ module Enumerable
14
14
  end
15
15
  end
16
16
 
17
- if RUBY_VERSION >= '2.6'
18
- warn "warning: Enumerable\#chain defined since Ruby 2.6 is incompatible with this gem when used with args and a block"
19
- undef chain
20
- end
21
-
22
- #
23
- # Creates a chain of Enumerables following this one, and
24
- # invokes a block once for each element of each Enumerable.
25
- #
26
- def chain *enums
27
- return enum_for(:chain, *enums) unless block_given?
28
- [self, *enums].each do |enum|
29
- enum.each {|*args| yield(*args) }
30
- end
31
- nil
32
- end
33
-
34
17
  end
35
18
 
36
19
  =begin
37
- Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
20
+ Copyright (c) 2018-2026, Matthew Kerwin <matthew@kerwin.net.au>
38
21
 
39
22
  Permission to use, copy, modify, and/or distribute this software for any
40
23
  purpose with or without fee is hereby granted, provided that the above
@@ -8,19 +8,12 @@ class MatchData
8
8
  # groups or not.
9
9
  def to_h
10
10
  if names.empty?
11
- Hash[ captures.each_with_index.map{|v,i| [i+1, v] } ]
11
+ captures.each_with_index.to_h{|v,i| [i+1, v] }
12
12
  else
13
- Hash[ names.map{|n| [n, self[n]] } ]
13
+ names.to_h{|n| [n, self[n]] }
14
14
  end
15
15
  end
16
16
 
17
- if RUBY_VERSION < '2.4'
18
- # Returns a Hash object of capture name => captured string.
19
- def named_captures
20
- Hash[ names.map{|n| [n, self[n]] } ]
21
- end
22
- end
23
-
24
17
  # Returns a Hash object of capture position => captured string.
25
18
  #
26
19
  # If +include_names+ is given and true, treats named captures
@@ -30,13 +23,13 @@ class MatchData
30
23
  # captures will be available using this method!
31
24
  def positional_captures include_names: false
32
25
  return {} unless names.empty? || include_names
33
- Hash[ captures.each_with_index.map{|v,i| [i+1, v] } ]
26
+ captures.each_with_index.to_h{|v,i| [i+1, v] }
34
27
  end
35
28
 
36
29
  end
37
30
 
38
31
  =begin
39
- Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
32
+ Copyright (c) 2018-2026, Matthew Kerwin <matthew@kerwin.net.au>
40
33
 
41
34
  Permission to use, copy, modify, and/or distribute this software for any
42
35
  purpose with or without fee is hereby granted, provided that the above
@@ -1,37 +1,53 @@
1
1
 
2
2
  class Numeric
3
3
 
4
- if RUBY_VERSION < '2.3'
5
- def negative?
6
- self < 0 ? self : nil
7
- end
4
+ def negative?
5
+ self < 0
6
+ end
8
7
 
9
- def positive?
10
- self > 0 ? self : nil
11
- end
8
+ def positive?
9
+ self > 0
12
10
  end
13
11
 
14
12
  def nonnegative?
15
- self < 0 ? nil : self
13
+ self >= 0
16
14
  end
17
15
 
18
16
  def nonpositive?
19
- self > 0 ? nil : self
17
+ self <= 0
18
+ end
19
+
20
+ def negative!
21
+ self < 0 ? self : nil
22
+ end
23
+
24
+ def positive!
25
+ self > 0 ? self : nil
26
+ end
27
+
28
+ def nonnegative!
29
+ self >= 0 ? self : nil
30
+ end
31
+
32
+ def nonpositive!
33
+ self <= 0 ? self : nil
20
34
  end
21
35
 
22
36
  end
23
37
 
24
38
  class Complex
25
- if RUBY_VERSION < '2.3'
26
- undef :negative?
27
- undef :positive?
28
- end
39
+ undef :negative? if method_defined?(:negative?)
40
+ undef :positive? if method_defined?(:positive?)
29
41
  undef :nonnegative?
30
42
  undef :nonpositive?
43
+ undef :negative!
44
+ undef :positive!
45
+ undef :nonnegative!
46
+ undef :nonpositive!
31
47
  end
32
48
 
33
49
  =begin
34
- Copyright (c) 2015, Matthew Kerwin <matthew@kerwin.net.au>
50
+ Copyright (c) 2015-2026, Matthew Kerwin <matthew@kerwin.net.au>
35
51
 
36
52
  Permission to use, copy, modify, and/or distribute this software for any
37
53
  purpose with or without fee is hereby granted, provided that the above
@@ -1,8 +1,8 @@
1
1
  class Test_clamp < Test::Unit::TestCase
2
2
 
3
3
  def test_clamp__endless_range
4
- rng = (1..)
5
- assert_raise(RangeError) { 2.clamp(rng) }
4
+ assert_equal( 2, 2.clamp(1..) )
5
+ assert_equal( 1, 0.clamp(1..) )
6
6
  end
7
7
 
8
8
  def test_bound__endless
@@ -1,8 +1,8 @@
1
1
  class Test_clamp < Test::Unit::TestCase
2
2
 
3
3
  def test_clamp__beginless_range
4
- rng = (..3)
5
- assert_raise(RangeError) { 2.clamp(rng) }
4
+ assert_equal( 2, 2.clamp(..3) )
5
+ assert_equal( 3, 5.clamp(..3) )
6
6
  end
7
7
 
8
8
  def test_bound__beginless
@@ -1,14 +1,6 @@
1
1
  require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
- if RUBY_VERSION.to_f < 1.9
5
- class Symbol
6
- def next
7
- to_s.next.to_sym
8
- end
9
- end
10
- end
11
-
12
4
  require_relative '../lib/mug/array/extend'
13
5
  class Test_array_extend < Test::Unit::TestCase
14
6
 
data/test/test-bool.rb CHANGED
@@ -10,13 +10,8 @@ class Test_bool < Test::Unit::TestCase
10
10
  def each(&b) @a.each(&b); end
11
11
  end
12
12
 
13
- if RUBY_VERSION.to_i >= 2
14
- TRUTHY = [ 1, 1.0, Float::INFINITY, -Float::INFINITY, (1<<100).coerce(1).first, Rational(1,1), "x", [1], {1=>1}, MyEnum.new(1), [1].each ]
15
- FALSY = [ 0, 0.0, -0.0, Float::NAN, (1<<100).coerce(0).first, Rational(0,1), "", [], {}, MyEnum.new, [].each, RuntimeError.new ]
16
- else
17
- TRUTHY = [ 1, 1.0, Float::INFINITY, -Float::INFINITY, (1<<100).coerce(1).first, Rational(1,1), "x", [1], {1=>1}, MyEnum.new(1) ]
18
- FALSY = [ 0, 0.0, -0.0, Float::NAN, (1<<100).coerce(0).first, Rational(0,1), "", [], {}, MyEnum.new, RuntimeError.new ]
19
- end
13
+ TRUTHY = [ 1, 1.0, Float::INFINITY, -Float::INFINITY, (1<<100).coerce(1).first, Rational(1,1), "x", [1], {1=>1}, MyEnum.new(1), [1].each ]
14
+ FALSY = [ 0, 0.0, -0.0, Float::NAN, (1<<100).coerce(0).first, Rational(0,1), "", [], {}, MyEnum.new, [].each, RuntimeError.new ]
20
15
 
21
16
  alias assert_true assert
22
17
  def assert_false val, msg=UNASSIGNED
data/test/test-clamp.rb CHANGED
@@ -22,11 +22,6 @@ class Test_clamp < Test::Unit::TestCase
22
22
  assert_equal( 3, 2.clamp(rng) )
23
23
  assert_equal( 4, 4.clamp(rng) )
24
24
  assert_equal( 5, 6.clamp(rng) )
25
-
26
- rng = 3...5
27
- assert_equal( 3, 2.clamp(rng) )
28
- assert_equal( 4, 4.clamp(rng) )
29
- assert_raise(ArgumentError) { 6.clamp(rng) }
30
25
  end
31
26
 
32
27
  def test_bound__inclusive
@@ -48,11 +43,6 @@ class Test_clamp < Test::Unit::TestCase
48
43
  end
49
44
  end
50
45
 
51
- if RUBY_VERSION.to_f >= 2.6
52
- require_relative '2-6-test-clamp'
53
- end
54
-
55
- if RUBY_VERSION.to_f >= 2.7
56
- require_relative '2-7-test-clamp'
57
- end
46
+ require_relative '2-6-test-clamp'
47
+ require_relative '2-7-test-clamp'
58
48
 
@@ -3,23 +3,6 @@ $VERBOSE = true
3
3
 
4
4
  require_relative '../lib/mug/enumerable/chain'
5
5
  class Test_enumerable_chain < Test::Unit::TestCase
6
- def test_chain
7
- a = [1, 2, 3, 4].each_with_index
8
- b = [5, 6].each_with_index
9
- c = [7, 8].each_with_index
10
- expect = [
11
- [1,0], [2,1], [3,2], [4,3],
12
- [5,0], [6,1],
13
- [7,0], [8,1],
14
- ]
15
-
16
- result = []
17
- a.chain(b, c) do |*x|
18
- result << x
19
- end
20
-
21
- assert_equal( expect, result )
22
- end
23
6
 
24
7
  def test_chain__noblock
25
8
  a = [1, 2, 3, 4].each_with_index
@@ -32,7 +15,8 @@ class Test_enumerable_chain < Test::Unit::TestCase
32
15
  ]
33
16
 
34
17
  enum = a.chain(b, c)
35
- assert_kind_of( Enumerator, enum )
18
+ assert( enum.kind_of?(Enumerator) || enum.kind_of?(Enumerator::Chain),
19
+ "expected Enumerator or Enumerator::Chain, got #{enum.class}" )
36
20
 
37
21
  result = []
38
22
  enum.each do |*x|
data/test/test-hashmap.rb CHANGED
@@ -1,14 +1,6 @@
1
1
  require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
- if RUBY_VERSION.to_f < 1.9
5
- class Symbol
6
- def next
7
- to_s.next.to_sym
8
- end
9
- end
10
- end
11
-
12
4
  require_relative '../lib/mug/hash/map'
13
5
  class Test_hashmap < Test::Unit::TestCase
14
6
  def test_hashmap
data/test/test-self.rb CHANGED
@@ -19,10 +19,6 @@ class Test_self < Test::Unit::TestCase
19
19
  p = proc {|*args| args }
20
20
  assert_equal( [1], 1.revapply(&p) )
21
21
  assert_equal( [1,2,3], 1.revapply(2,3,&p) )
22
- if RUBY_VERSION.to_i >= 2
23
- assert_equal( 3, 1.revapply(2,3).size )
24
- else
25
- assert_equal( [1,2,3], 1.revapply(2,3).first )
26
- end
22
+ assert_equal( 3, 1.revapply(2,3).size )
27
23
  end
28
24
  end
data/test/test-tau.rb CHANGED
@@ -12,8 +12,8 @@ class Test_tau < Test::Unit::TestCase
12
12
 
13
13
  include BigMath
14
14
  def test_TAU
15
- assert_equal(TAU(1).round(1).to_s('F'), '6.3')
16
- assert_equal(TAU(100).truncate(100).to_s('F'), '6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359')
15
+ assert_equal(TAU(3).round(1).to_s('F'), '6.3')
16
+ assert_equal(TAU(102).truncate(100).to_s('F'), '6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359')
17
17
  assert_raise(ArgumentError) { TAU(0) }
18
18
  assert_raise(ArgumentError) { TAU(-3) }
19
19
  assert_raise(ArgumentError) { TAU('barf') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2026-04-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == MUG: Matty's Ultimate Gem
@@ -117,7 +117,7 @@ homepage: http://phluid61.github.com/mug
117
117
  licenses:
118
118
  - ISC
119
119
  metadata: {}
120
- post_install_message:
120
+ post_install_message:
121
121
  rdoc_options: []
122
122
  require_paths:
123
123
  - lib
@@ -125,15 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - ">="
127
127
  - !ruby/object:Gem::Version
128
- version: '0'
128
+ version: '2.7'
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.1.4
136
- signing_key:
135
+ rubygems_version: 3.3.15
136
+ signing_key:
137
137
  specification_version: 4
138
138
  summary: 'MUG: Matty''s Ultimate Gem'
139
139
  test_files: