shenanigans 1.0.13 → 1.0.14

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/doc/Array.html +104 -74
  4. data/doc/Hash.html +77 -56
  5. data/doc/{Fixnum.html → Integer.html} +31 -27
  6. data/doc/Kernel.html +114 -74
  7. data/doc/Module.html +11 -15
  8. data/doc/Object.html +24 -95
  9. data/doc/String.html +31 -30
  10. data/doc/_index.html +13 -13
  11. data/doc/class_list.html +3 -3
  12. data/doc/css/style.css +6 -9
  13. data/doc/file.README.html +19 -48
  14. data/doc/file_list.html +2 -2
  15. data/doc/frames.html +2 -2
  16. data/doc/index.html +19 -48
  17. data/doc/js/app.js +69 -3
  18. data/doc/method_list.html +12 -20
  19. data/doc/top-level-namespace.html +7 -7
  20. data/lib/shenanigans.rb +7 -7
  21. data/lib/shenanigans/array.rb +3 -3
  22. data/lib/shenanigans/array/caret.rb +3 -2
  23. data/lib/shenanigans/array/random_subarray.rb +7 -5
  24. data/lib/shenanigans/array/reductions.rb +13 -10
  25. data/lib/shenanigans/array/zip_with.rb +9 -12
  26. data/lib/shenanigans/hash.rb +3 -3
  27. data/lib/shenanigans/hash/extract.rb +5 -4
  28. data/lib/shenanigans/hash/has_shape_pred.rb +6 -7
  29. data/lib/shenanigans/hash/to_ostruct.rb +8 -9
  30. data/lib/shenanigans/integer.rb +1 -0
  31. data/lib/shenanigans/integer/string_length.rb +13 -0
  32. data/lib/shenanigans/kernel.rb +4 -4
  33. data/lib/shenanigans/kernel/fn.rb +7 -6
  34. data/lib/shenanigans/kernel/prompt.rb +6 -7
  35. data/lib/shenanigans/kernel/require_optional.rb +8 -8
  36. data/lib/shenanigans/kernel/with.rb +4 -3
  37. data/lib/shenanigans/module.rb +1 -1
  38. data/lib/shenanigans/module/private_accessor.rb +6 -6
  39. data/lib/shenanigans/object.rb +1 -2
  40. data/lib/shenanigans/object/display.rb +5 -4
  41. data/lib/shenanigans/string.rb +2 -2
  42. data/lib/shenanigans/string/cmpi.rb +4 -3
  43. data/lib/shenanigans/string/in_groups_of.rb +4 -6
  44. data/test/array/caret_test.rb +9 -0
  45. data/test/array/{test_random_subarray.rb → random_subarray_test.rb} +3 -3
  46. data/test/array/reductions_test.rb +27 -0
  47. data/test/array/zip_with_test.rb +14 -0
  48. data/test/hash/extract_test.rb +11 -0
  49. data/test/hash/{test_has_shape_pred.rb → has_shape_pred_test.rb} +3 -3
  50. data/test/hash/{test_to_ostruct.rb → to_ostruct_test.rb} +3 -3
  51. data/test/integer/string_length_test.rb +16 -0
  52. data/test/kernel/fn_test.rb +14 -0
  53. data/test/kernel/{test_prompt.rb → prompt_test.rb} +4 -4
  54. data/test/kernel/require_optional_test.rb +15 -0
  55. data/test/kernel/with_test.rb +12 -0
  56. data/test/module/{test_private_accessor.rb → private_accessor_test.rb} +3 -3
  57. data/test/object/{test_display.rb → display_test.rb} +4 -5
  58. data/test/string/{test_cmpi.rb → cmpi_test.rb} +3 -3
  59. data/test/string/in_groups_of_test.rb +11 -0
  60. metadata +22 -25
  61. data/lib/shenanigans/fixnum.rb +0 -1
  62. data/lib/shenanigans/fixnum/string_length.rb +0 -14
  63. data/lib/shenanigans/object/it.rb +0 -9
  64. data/test/array/test_caret.rb +0 -9
  65. data/test/array/test_reductions.rb +0 -27
  66. data/test/array/test_zip_with.rb +0 -14
  67. data/test/fixnum/test_string_length.rb +0 -16
  68. data/test/hash/test_extract.rb +0 -11
  69. data/test/kernel/test_fn.rb +0 -14
  70. data/test/kernel/test_require_optional.rb +0 -17
  71. data/test/kernel/test_with.rb +0 -12
  72. data/test/object/test_it.rb +0 -10
  73. data/test/string/test_in_groups_of.rb +0 -11
@@ -1,14 +1,12 @@
1
1
  class String
2
2
  # Returns an array of the string broken down into groups of
3
3
  # <tt>size</tt> characters.
4
- # "aabbcc".in_groups_of(2)
5
- # #=> ['aa', 'bb', 'cc']
6
- # "".in_groups_of(2)
7
- # #=> []
8
- # "".in_groups_of(0)
9
- # #=> ArgumentError
4
+ # "aabbcc".in_groups_of(2) #=> ['aa', 'bb', 'cc']
5
+ # "".in_groups_of(2) #=> []
6
+ # "".in_groups_of(0) #=> ArgumentError
10
7
  def in_groups_of(size)
11
8
  raise ArgumentError, "Size of group must be >= 1" if size < 1
9
+
12
10
  scan(/.{1,#{size}}/)
13
11
  end
14
12
  end
@@ -0,0 +1,9 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/array/caret"
3
+
4
+ class ArrayCaret < Minitest::Test
5
+ def test_caret
6
+ result = [1, 2, 3] ^ [1, 2, 4]
7
+ assert result == [3, 4]
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/array/random_subarray'
1
+ require "minitest/autorun"
2
+ require "shenanigans/array/random_subarray"
3
3
 
4
- class RandomSubarray < MiniTest::Unit::TestCase
4
+ class RandomSubarray < Minitest::Test
5
5
  def test_random_subarray
6
6
  result = [*1..5].random_subarray(3)
7
7
  assert result.size == 3
@@ -0,0 +1,27 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/array/reductions"
3
+
4
+ class ArrayReductions < Minitest::Test
5
+ TEST_ARRAY = [*1..4]
6
+
7
+ def test_reductions_without_params_or_block
8
+ assert_raises(ArgumentError) { TEST_ARRAY.reductions }
9
+ end
10
+
11
+ def test_reductions_operator_only
12
+ assert TEST_ARRAY.reductions(:+) == [1, 3, 6, 10]
13
+ end
14
+
15
+ def test_reductions_initial_only
16
+ assert TEST_ARRAY.reductions(50) { |acc, b| acc + b } == [50, 51, 53, 56, 60]
17
+ end
18
+
19
+ def test_reductions_inital_and_operator
20
+ assert TEST_ARRAY.reductions(50, :+) == [50, 51, 53, 56, 60]
21
+ end
22
+
23
+ def test_reductions_without_params
24
+ assert TEST_ARRAY.reductions { |acc, b| acc + b } == [1, 3, 6, 10]
25
+ assert %w[a b c].reductions { |s1, s2| s1 + s2 } == %w[a ab abc]
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/array/zip_with"
3
+
4
+ class ZipWith < Minitest::Test
5
+ def test_zip_with_with_symbol
6
+ result = [*1..3].zip_with([*1..3], :+)
7
+ assert result == [2, 4, 6]
8
+ end
9
+
10
+ def test_zip_with_with_block
11
+ result = [*"a".."c"].zip_with([*"a".."c"]) { |a, b| a * 2 + b.upcase }
12
+ assert result == %w[aaA bbB ccC]
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/hash/extract"
3
+
4
+ class Extract < Minitest::Test
5
+ def test_extract
6
+ hash = { a: 1, b: 2, c: 3 }
7
+ assert_equal hash.extract(:b, :a), { a: 1, b: 2 }
8
+ assert_equal hash.extract(:a, :d), { a: 1 }
9
+ assert_equal({}.extract(:a, :c), {})
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/hash/has_shape_pred'
1
+ require "minitest/autorun"
2
+ require "shenanigans/hash/has_shape_pred"
3
3
 
4
- class HasShape < MiniTest::Unit::TestCase
4
+ class HasShape < Minitest::Test
5
5
  def setup
6
6
  @hash = {
7
7
  k1: 1.0,
@@ -1,7 +1,7 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/hash/to_ostruct'
1
+ require "minitest/autorun"
2
+ require "shenanigans/hash/to_ostruct"
3
3
 
4
- class ToOstruct < MiniTest::Unit::TestCase
4
+ class ToOstruct < Minitest::Test
5
5
  def test_simple_hash
6
6
  struct = {a: 1, b: 2}.to_ostruct
7
7
  assert struct.a == 1
@@ -0,0 +1,16 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/integer/string_length"
3
+
4
+ class StringLength < Minitest::Test
5
+ def test_zero
6
+ assert 0.string_length == 1
7
+ end
8
+
9
+ def test_positive
10
+ assert 123.string_length == 3
11
+ end
12
+
13
+ def test_negative
14
+ assert(-1.string_length) == 2
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/kernel/fn"
3
+
4
+ class Fn < Minitest::Test
5
+ def test_with_symbols
6
+ result = ["foo bar", "baz qux"].map(&fn(:split, :last))
7
+ assert result == ["bar", "qux"]
8
+ end
9
+
10
+ def test_with_symbols_and_lambdas
11
+ result = (1..3).map(&fn(:next, ->(x) { x * x }, ->(x) { x.to_f / 2 }))
12
+ assert result == [2.0, 4.5, 8.0]
13
+ end
14
+ end
@@ -1,8 +1,8 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/kernel/prompt'
3
- require 'stringio'
1
+ require "minitest/autorun"
2
+ require "shenanigans/kernel/prompt"
3
+ require "stringio"
4
4
 
5
- class Prompt < MiniTest::Unit::TestCase
5
+ class Prompt < Minitest::Test
6
6
  def setup
7
7
  @orig_stdin = $stderr
8
8
  @orig_stdout = $stdout
@@ -0,0 +1,15 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/kernel/require_optional"
3
+ require "stringio"
4
+
5
+ class RequireOptional < Minitest::Test
6
+ def test_require_optional
7
+ assert_nil require_optional("non_existent")
8
+ end
9
+
10
+ def test_require_optional_with_block
11
+ res = require_optional("non_existent") { 42 }
12
+
13
+ assert_equal res, 42
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/kernel/with"
3
+
4
+ class With < Minitest::Test
5
+ def test_with
6
+ result = with([]) { |a|
7
+ a << "a"
8
+ a << "b"
9
+ }
10
+ assert result == %w[a b]
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/module/private_accessor'
1
+ require "minitest/autorun"
2
+ require "shenanigans/module/private_accessor"
3
3
 
4
- class PrivateAccessor < MiniTest::Unit::TestCase
4
+ class PrivateAccessor < Minitest::Test
5
5
  class Foo
6
6
  private_accessor :bar, :baz
7
7
 
@@ -1,8 +1,8 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/object/display'
3
- require 'stringio'
1
+ require "minitest/autorun"
2
+ require "shenanigans/object/display"
3
+ require "stringio"
4
4
 
5
- class Display < MiniTest::Unit::TestCase
5
+ class Display < Minitest::Test
6
6
  def setup
7
7
  @orig_stdout = $stdout
8
8
  $stdout = StringIO.new("", "r+")
@@ -32,5 +32,4 @@ class Display < MiniTest::Unit::TestCase
32
32
  $stdout.rewind
33
33
  assert $stdout.gets == str
34
34
  end
35
-
36
35
  end
@@ -1,7 +1,7 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/string/cmpi'
1
+ require "minitest/autorun"
2
+ require "shenanigans/string/cmpi"
3
3
 
4
- class Cmpi < MiniTest::Unit::TestCase
4
+ class Cmpi < Minitest::Test
5
5
  def cmpi
6
6
  str = "aabbcc"
7
7
  assert str.cmpi("AAbbcc")
@@ -0,0 +1,11 @@
1
+ require "minitest/autorun"
2
+ require "shenanigans/string/in_groups_of"
3
+
4
+ class InGroupsOf < Minitest::Test
5
+ def test_in_groups_of
6
+ str = "aabbcc"
7
+ assert str.in_groups_of(2) == ["aa", "bb", "cc"]
8
+ assert "".in_groups_of(2) == []
9
+ assert_raises(ArgumentError) { "".in_groups_of(0) }
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shenanigans
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kohl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A collection of extensions for various Ruby core classes.
14
14
  email: citizen428@gmail.com
@@ -20,8 +20,8 @@ files:
20
20
  - LICENSE
21
21
  - README.rdoc
22
22
  - doc/Array.html
23
- - doc/Fixnum.html
24
23
  - doc/Hash.html
24
+ - doc/Integer.html
25
25
  - doc/Kernel.html
26
26
  - doc/Module.html
27
27
  - doc/Object.html
@@ -46,12 +46,12 @@ files:
46
46
  - lib/shenanigans/array/random_subarray.rb
47
47
  - lib/shenanigans/array/reductions.rb
48
48
  - lib/shenanigans/array/zip_with.rb
49
- - lib/shenanigans/fixnum.rb
50
- - lib/shenanigans/fixnum/string_length.rb
51
49
  - lib/shenanigans/hash.rb
52
50
  - lib/shenanigans/hash/extract.rb
53
51
  - lib/shenanigans/hash/has_shape_pred.rb
54
52
  - lib/shenanigans/hash/to_ostruct.rb
53
+ - lib/shenanigans/integer.rb
54
+ - lib/shenanigans/integer/string_length.rb
55
55
  - lib/shenanigans/kernel.rb
56
56
  - lib/shenanigans/kernel/fn.rb
57
57
  - lib/shenanigans/kernel/prompt.rb
@@ -61,27 +61,25 @@ files:
61
61
  - lib/shenanigans/module/private_accessor.rb
62
62
  - lib/shenanigans/object.rb
63
63
  - lib/shenanigans/object/display.rb
64
- - lib/shenanigans/object/it.rb
65
64
  - lib/shenanigans/string.rb
66
65
  - lib/shenanigans/string/cmpi.rb
67
66
  - lib/shenanigans/string/in_groups_of.rb
68
- - test/array/test_caret.rb
69
- - test/array/test_random_subarray.rb
70
- - test/array/test_reductions.rb
71
- - test/array/test_zip_with.rb
72
- - test/fixnum/test_string_length.rb
73
- - test/hash/test_extract.rb
74
- - test/hash/test_has_shape_pred.rb
75
- - test/hash/test_to_ostruct.rb
76
- - test/kernel/test_fn.rb
77
- - test/kernel/test_prompt.rb
78
- - test/kernel/test_require_optional.rb
79
- - test/kernel/test_with.rb
80
- - test/module/test_private_accessor.rb
81
- - test/object/test_display.rb
82
- - test/object/test_it.rb
83
- - test/string/test_cmpi.rb
84
- - test/string/test_in_groups_of.rb
67
+ - test/array/caret_test.rb
68
+ - test/array/random_subarray_test.rb
69
+ - test/array/reductions_test.rb
70
+ - test/array/zip_with_test.rb
71
+ - test/hash/extract_test.rb
72
+ - test/hash/has_shape_pred_test.rb
73
+ - test/hash/to_ostruct_test.rb
74
+ - test/integer/string_length_test.rb
75
+ - test/kernel/fn_test.rb
76
+ - test/kernel/prompt_test.rb
77
+ - test/kernel/require_optional_test.rb
78
+ - test/kernel/with_test.rb
79
+ - test/module/private_accessor_test.rb
80
+ - test/object/display_test.rb
81
+ - test/string/cmpi_test.rb
82
+ - test/string/in_groups_of_test.rb
85
83
  homepage: http://rubydoc.info/gems/shenanigans/frames
86
84
  licenses:
87
85
  - MIT
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
103
101
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.7.3
102
+ rubygems_version: 3.1.2
106
103
  signing_key:
107
104
  specification_version: 4
108
105
  summary: Think Facets, just less useful
@@ -1 +0,0 @@
1
- require_relative 'fixnum/string_length'
@@ -1,14 +0,0 @@
1
- class Fixnum
2
- # Returns the length of the number's string representation.
3
- # 0.string_length
4
- # #=> 1
5
- # 123.string_length
6
- # #=> 3
7
- # -1.string_length
8
- # #=> 2
9
- def string_length
10
- return 1 if self.zero?
11
- len = Math.log10(self.abs).floor.next
12
- self > 0 ? len : len.next
13
- end
14
- end
@@ -1,9 +0,0 @@
1
- class Object
2
- # An identity method that provides access to an object's
3
- # <tt>self</tt>.
4
- # [1,2,3,4,5,1,2,2,3].group_by(&:it)
5
- # #=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
6
- def it
7
- self
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/array/caret'
3
-
4
- class ArrayCaret < MiniTest::Unit::TestCase
5
- def test_caret
6
- result = [1, 2, 3] ^ [1, 2, 4]
7
- assert result == [3, 4]
8
- end
9
- end
@@ -1,27 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/array/reductions'
3
-
4
- class ArrayReductions < MiniTest::Unit::TestCase
5
- TEST_ARRAY = [*1..4]
6
-
7
- def test_reductions_without_params_or_block
8
- assert_raises(ArgumentError) { TEST_ARRAY.reductions }
9
- end
10
-
11
- def test_reductions_operator_only
12
- assert TEST_ARRAY.reductions(:+) == [1,3,6,10]
13
- end
14
-
15
- def test_reductions_initial_only
16
- assert TEST_ARRAY.reductions(50) { |acc,b| acc+b} == [50,51,53,56,60]
17
- end
18
-
19
- def test_reductions_inital_and_operator
20
- assert TEST_ARRAY.reductions(50, :+) == [50,51,53,56,60]
21
- end
22
-
23
- def test_reductions_without_params
24
- assert TEST_ARRAY.reductions { |acc,b| acc+b} == [1,3,6,10]
25
- assert %w(a b c).reductions { |s1, s2| s1+s2 } == %w(a ab abc)
26
- end
27
- end
@@ -1,14 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/array/zip_with'
3
-
4
- class ZipWith < MiniTest::Unit::TestCase
5
- def test_zip_with_with_symbol
6
- result = [*1..3].zip_with([*1..3], :+)
7
- assert result == [2, 4, 6]
8
- end
9
-
10
- def test_zip_with_with_block
11
- result = [*?a..?c].zip_with([*?a..?c]) { |a, b| a * 2 + b.upcase }
12
- assert result == %w(aaA bbB ccC)
13
- end
14
- end
@@ -1,16 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'shenanigans/fixnum/string_length'
3
-
4
- class StringLength < MiniTest::Unit::TestCase
5
- def test_zero
6
- assert 0.string_length == 1
7
- end
8
-
9
- def test_positive
10
- assert 123.string_length == 3
11
- end
12
-
13
- def test_negative
14
- assert -1.string_length == 2
15
- end
16
- end