shenanigans 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Gemfile +5 -0
  2. data/LICENSE +7 -0
  3. data/README.rdoc +57 -0
  4. data/doc/Array.html +240 -0
  5. data/doc/Kernel.html +283 -0
  6. data/doc/Object.html +179 -0
  7. data/doc/README_rdoc.html +174 -0
  8. data/doc/created.rid +12 -0
  9. data/doc/images/add.png +0 -0
  10. data/doc/images/brick.png +0 -0
  11. data/doc/images/brick_link.png +0 -0
  12. data/doc/images/bug.png +0 -0
  13. data/doc/images/bullet_black.png +0 -0
  14. data/doc/images/bullet_toggle_minus.png +0 -0
  15. data/doc/images/bullet_toggle_plus.png +0 -0
  16. data/doc/images/date.png +0 -0
  17. data/doc/images/delete.png +0 -0
  18. data/doc/images/find.png +0 -0
  19. data/doc/images/loadingAnimation.gif +0 -0
  20. data/doc/images/macFFBgHack.png +0 -0
  21. data/doc/images/package.png +0 -0
  22. data/doc/images/page_green.png +0 -0
  23. data/doc/images/page_white_text.png +0 -0
  24. data/doc/images/page_white_width.png +0 -0
  25. data/doc/images/plugin.png +0 -0
  26. data/doc/images/ruby.png +0 -0
  27. data/doc/images/tag_blue.png +0 -0
  28. data/doc/images/tag_green.png +0 -0
  29. data/doc/images/transparent.png +0 -0
  30. data/doc/images/wrench.png +0 -0
  31. data/doc/images/wrench_orange.png +0 -0
  32. data/doc/images/zoom.png +0 -0
  33. data/doc/index.html +173 -0
  34. data/doc/js/darkfish.js +153 -0
  35. data/doc/js/jquery.js +18 -0
  36. data/doc/js/navigation.js +142 -0
  37. data/doc/js/search.js +94 -0
  38. data/doc/js/search_index.js +1 -0
  39. data/doc/js/searcher.js +228 -0
  40. data/doc/rdoc.css +543 -0
  41. data/doc/table_of_contents.html +82 -0
  42. data/lib/shenanigans/README.mdown +57 -0
  43. data/lib/shenanigans/array/random_subarray.rb +16 -0
  44. data/lib/shenanigans/array/zip_with.rb +27 -0
  45. data/lib/shenanigans/array.rb +2 -0
  46. data/lib/shenanigans/kernel/fn.rb +16 -0
  47. data/lib/shenanigans/kernel/prompt.rb +23 -0
  48. data/lib/shenanigans/kernel/with.rb +12 -0
  49. data/lib/shenanigans/kernel.rb +3 -0
  50. data/lib/shenanigans/object/identity.rb +9 -0
  51. data/lib/shenanigans/object.rb +1 -0
  52. data/lib/shenanigans/shenanigans-0.0.1.gem +0 -0
  53. data/lib/shenanigans.rb +3 -0
  54. data/test/array/test_random_subarray.rb +10 -0
  55. data/test/array/test_zip_with.rb +14 -0
  56. data/test/kernel/test_fn.rb +14 -0
  57. data/test/kernel/test_prompt.rb +27 -0
  58. data/test/kernel/test_with.rb +12 -0
  59. data/test/object/test_identity.rb +9 -0
  60. metadata +103 -0
@@ -0,0 +1,2 @@
1
+ require_relative "array/random_subarray"
2
+ require_relative "array/zip_with"
@@ -0,0 +1,16 @@
1
+ module Kernel
2
+ # Composes a list of functions.
3
+ # Functions can be specified as symbols or lambdas.
4
+ # ["foo bar", "baz qux"].map &fn(:split, :last)
5
+ # #=> ["bar", "qux"]
6
+ #
7
+ # (1..3).map &fn(:next, -> x { x * x }, -> x { x.to_f / 2 } )
8
+ # #=> [2.0, 4.5, 8.0]
9
+ def fn(*funs)
10
+ -> x do
11
+ funs.inject(x) do |v,f|
12
+ Proc === f ? f.call(v) : v.send(f)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ module Kernel
2
+
3
+ # Currently only used by <tt>prompt</tt>:
4
+ # <tt>:to_i</tt>, <tt>:to_f</tt>, <tt>:to_r</tt>, <tt>:to_sym</tt>, <tt>:to_c</tt>
5
+ CONVERSIONS = [:to_i, :to_f, :to_r, :to_sym, :to_c]
6
+
7
+ # Displays a prompt and returns chomped input.
8
+ # Modelled after the Python method <tt>raw_input</tt>, but also can
9
+ # be supplied with an optional conversion method.
10
+ # prompt("Prompt> ")
11
+ # Prompt> 12
12
+ # #=> "12"
13
+ #
14
+ # prompt("Prompt> ", :to_f)
15
+ # Prompt> 12
16
+ # #=> 12.0
17
+ def prompt(text='', conversion=nil)
18
+ print text unless text.empty?
19
+ input = gets.chomp
20
+ CONVERSIONS.include?(conversion) ? input.send(conversion) : input
21
+ end
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ module Kernel
2
+ # A Pascal/ActionScript like <tt>with</tt> method. Yields its
3
+ # argument to the provided block and then returns it.
4
+ # with([]) do |a|
5
+ # a << "a"
6
+ # a << "b"
7
+ # end
8
+ # #=> ["a", "b"]
9
+ def with(o, &blk)
10
+ o.tap(&blk)
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "kernel/fn"
2
+ require_relative "kernel/prompt"
3
+ require_relative "kernel/with"
@@ -0,0 +1,9 @@
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(&:identity)
5
+ # #=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
6
+ def identity
7
+ self
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require_relative "object/identity"
@@ -0,0 +1,3 @@
1
+ require 'shenanigans/array'
2
+ require 'shenanigans/kernel'
3
+ require 'shenanigans/object'
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/array/random_subarray'
3
+
4
+ class RandomSubarray < MiniTest::Unit::TestCase
5
+ def test_random_subarray
6
+ result = [*1..5].random_subarray(3)
7
+ assert result.size == 3
8
+ assert result.map { |a| a.all? { |x| x < 5 } }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,14 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/kernel/fn'
3
+
4
+ class Fn < MiniTest::Unit::TestCase
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
@@ -0,0 +1,27 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/kernel/prompt'
3
+ require 'stringio'
4
+
5
+ class Prompt < MiniTest::Unit::TestCase
6
+ def setup
7
+ @orig_stdin = $stderr
8
+ @orig_stdout = $stdout
9
+ $stdin = StringIO.new("42\n")
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ def teardown
14
+ $stdin = @orig_stdin
15
+ $stdout = @orig_stdout
16
+ end
17
+
18
+ def test_prompt
19
+ result = prompt("Foo> ")
20
+ assert result == "42"
21
+ end
22
+
23
+ def test_prompt_with_conversion
24
+ result = prompt("Foo> ", :to_f)
25
+ assert result == 42.0
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/kernel/with'
3
+
4
+ class With < MiniTest::Unit::TestCase
5
+ def test_with
6
+ result = with([]) do |a|
7
+ a << "a"
8
+ a << "b"
9
+ end
10
+ assert result == %w(a b)
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/object/identity'
3
+
4
+ class Identity < MiniTest::Unit::TestCase
5
+ def test_identity
6
+ arr = [1, "2", :tree]
7
+ assert arr.map(&:identity) == arr
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shenanigans
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Kohl
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-17 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: citizen428@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - LICENSE
22
+ - README.rdoc
23
+ - doc/Array.html
24
+ - doc/created.rid
25
+ - doc/images/add.png
26
+ - doc/images/brick.png
27
+ - doc/images/brick_link.png
28
+ - doc/images/bug.png
29
+ - doc/images/bullet_black.png
30
+ - doc/images/bullet_toggle_minus.png
31
+ - doc/images/bullet_toggle_plus.png
32
+ - doc/images/date.png
33
+ - doc/images/delete.png
34
+ - doc/images/find.png
35
+ - doc/images/loadingAnimation.gif
36
+ - doc/images/macFFBgHack.png
37
+ - doc/images/package.png
38
+ - doc/images/page_green.png
39
+ - doc/images/page_white_text.png
40
+ - doc/images/page_white_width.png
41
+ - doc/images/plugin.png
42
+ - doc/images/ruby.png
43
+ - doc/images/tag_blue.png
44
+ - doc/images/tag_green.png
45
+ - doc/images/transparent.png
46
+ - doc/images/wrench.png
47
+ - doc/images/wrench_orange.png
48
+ - doc/images/zoom.png
49
+ - doc/index.html
50
+ - doc/js/darkfish.js
51
+ - doc/js/jquery.js
52
+ - doc/js/navigation.js
53
+ - doc/js/search.js
54
+ - doc/js/search_index.js
55
+ - doc/js/searcher.js
56
+ - doc/Kernel.html
57
+ - doc/Object.html
58
+ - doc/rdoc.css
59
+ - doc/README_rdoc.html
60
+ - doc/table_of_contents.html
61
+ - lib/shenanigans/array/random_subarray.rb
62
+ - lib/shenanigans/array/zip_with.rb
63
+ - lib/shenanigans/array.rb
64
+ - lib/shenanigans/kernel/fn.rb
65
+ - lib/shenanigans/kernel/prompt.rb
66
+ - lib/shenanigans/kernel/with.rb
67
+ - lib/shenanigans/kernel.rb
68
+ - lib/shenanigans/object/identity.rb
69
+ - lib/shenanigans/object.rb
70
+ - lib/shenanigans/README.mdown
71
+ - lib/shenanigans/shenanigans-0.0.1.gem
72
+ - lib/shenanigans.rb
73
+ - test/array/test_random_subarray.rb
74
+ - test/array/test_zip_with.rb
75
+ - test/kernel/test_fn.rb
76
+ - test/kernel/test_prompt.rb
77
+ - test/kernel/test_with.rb
78
+ - test/object/test_identity.rb
79
+ homepage: https://github.com/citizen428/shenanigans
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.23
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Think Facets, just less useful
103
+ test_files: []