shenanigans 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e639585c0a10a2b2821715d281053674c79ea3ad
4
+ data.tar.gz: 54aba9ba5e55964094affdbc1c40ca48c8387907
5
+ SHA512:
6
+ metadata.gz: 21d0fc654a799f2f3ae8e1d20307344639946a4102ebcbe7968a75cae06e2e1da5c58fd3df5bcf7bc184d9b1a104694604ce347e1e27b0f0900ef137c4b42080
7
+ data.tar.gz: e2148cfd423f6cad95c5c313299d4b40975858a4d4f0128de648197463d3370e9ecd091577393e43a57bb2dc4706f28b74ec7177e14d1069e06da360a4ebc30b
@@ -26,11 +26,11 @@ class Hash
26
26
  when Hash
27
27
  [k, v.to_ostruct]
28
28
  when Array
29
- [k, v.map { |el| Hash === el ? el.to_ostruct : el }]
29
+ [k, v.map { |el| el.respond_to?(:to_ostruct) ? el.to_ostruct : el }]
30
30
  else
31
31
  [k, v]
32
32
  end
33
33
  end
34
- OpenStruct.new(arr)
34
+ OpenStruct.new(Hash[arr])
35
35
  end
36
36
  end
@@ -0,0 +1 @@
1
+ require_relative "module/private_accessor"
@@ -0,0 +1,24 @@
1
+ class Module
2
+ private
3
+
4
+ # Works like <tt>attr_accessor</tt> but generates private
5
+ # getter/setter methods for class internal use only. Useful
6
+ # for enforcing Smalltalk-style internal encapsulation.
7
+ def private_accessor(*names)
8
+ names.each do |name|
9
+ instance_var_name = "@#{name}"
10
+
11
+ define_method(name) do
12
+ instance_variable_get(instance_var_name)
13
+ end
14
+
15
+ define_method("#{name}=") do |value|
16
+ instance_variable_set(instance_var_name, value)
17
+ end
18
+
19
+ self.send(:private, name)
20
+ self.send(:private, "#{name}=")
21
+ end
22
+ nil # like attr_accessor
23
+ end
24
+ end
@@ -4,16 +4,19 @@ require 'shenanigans/hash/to_ostruct'
4
4
  class ToOstruct < MiniTest::Unit::TestCase
5
5
  def test_simple_hash
6
6
  struct = {a: 1, b: 2}.to_ostruct
7
+ assert struct.a == 1
7
8
  assert struct.b == 2
8
9
  end
9
10
 
10
11
  def test_nested_hash
11
12
  struct = {a: 1, b: {c: 3}}.to_ostruct
13
+ assert struct.a == 1
12
14
  assert struct.b.c == 3
13
15
  end
14
16
 
15
17
  def test_nested_array
16
18
  struct = {a: 1, b: [{c: 2}, 5]}.to_ostruct
19
+ assert struct.a == 1
17
20
  assert struct.b.first.c == 2
18
21
  assert struct.b.last == 5
19
22
  end
@@ -0,0 +1,21 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/module/private_accessor'
3
+
4
+ class PrivateAccessor < MiniTest::Unit::TestCase
5
+ class Foo
6
+ private_accessor :bar, :baz
7
+
8
+ def initialize(v1, v2)
9
+ self.bar = v1
10
+ self.baz = v2
11
+ end
12
+ end
13
+
14
+ def test_private_accessor
15
+ f = Foo.new(1, 2)
16
+ assert f.instance_variables == [:@bar, :@baz]
17
+ assert (f.private_methods & [:bar, :baz, :bar=, :baz=]).size == 4
18
+ assert f.instance_variable_get("@bar") == 1
19
+ assert f.instance_variable_get("@baz") == 2
20
+ end
21
+ end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shenanigans
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
5
- prerelease:
4
+ version: 1.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Kohl
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
11
+ date: 2013-10-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description:
13
+ description: A collection of extensions for various Ruby core classes.
15
14
  email: citizen428@gmail.com
16
15
  executables: []
17
16
  extensions: []
@@ -20,105 +19,107 @@ files:
20
19
  - Gemfile
21
20
  - LICENSE
22
21
  - README.rdoc
23
- - doc/Array.html
24
- - doc/created.rid
25
22
  - doc/Fixnum.html
23
+ - doc/Object.html
26
24
  - doc/Hash.html
27
- - doc/images/add.png
28
- - doc/images/brick.png
29
- - doc/images/brick_link.png
30
- - doc/images/bug.png
31
25
  - doc/images/bullet_black.png
32
26
  - doc/images/bullet_toggle_minus.png
33
- - doc/images/bullet_toggle_plus.png
27
+ - doc/images/tag_blue.png
28
+ - doc/images/plugin.png
29
+ - doc/images/page_white_text.png
30
+ - doc/images/brick.png
31
+ - doc/images/page_white_width.png
32
+ - doc/images/wrench_orange.png
33
+ - doc/images/package.png
34
34
  - doc/images/date.png
35
- - doc/images/delete.png
35
+ - doc/images/bug.png
36
+ - doc/images/brick_link.png
37
+ - doc/images/tag_green.png
36
38
  - doc/images/find.png
37
- - doc/images/loadingAnimation.gif
38
- - doc/images/macFFBgHack.png
39
- - doc/images/package.png
40
39
  - doc/images/page_green.png
41
- - doc/images/page_white_text.png
42
- - doc/images/page_white_width.png
43
- - doc/images/plugin.png
44
40
  - doc/images/ruby.png
45
- - doc/images/tag_blue.png
46
- - doc/images/tag_green.png
41
+ - doc/images/zoom.png
47
42
  - doc/images/transparent.png
43
+ - doc/images/delete.png
48
44
  - doc/images/wrench.png
49
- - doc/images/wrench_orange.png
50
- - doc/images/zoom.png
45
+ - doc/images/bullet_toggle_plus.png
46
+ - doc/images/loadingAnimation.gif
47
+ - doc/images/add.png
48
+ - doc/images/macFFBgHack.png
51
49
  - doc/index.html
52
- - doc/js/darkfish.js
50
+ - doc/table_of_contents.html
51
+ - doc/rdoc.css
52
+ - doc/Array.html
53
+ - doc/String.html
54
+ - doc/created.rid
55
+ - doc/Kernel.html
53
56
  - doc/js/jquery.js
54
- - doc/js/navigation.js
55
- - doc/js/search.js
56
57
  - doc/js/search_index.js
57
58
  - doc/js/searcher.js
58
- - doc/Kernel.html
59
- - doc/Object.html
60
- - doc/rdoc.css
59
+ - doc/js/navigation.js
60
+ - doc/js/search.js
61
+ - doc/js/darkfish.js
61
62
  - doc/README_rdoc.html
62
- - doc/String.html
63
- - doc/table_of_contents.html
63
+ - lib/shenanigans.rb
64
+ - lib/shenanigans/fixnum/string_length.rb
65
+ - lib/shenanigans/object.rb
66
+ - lib/shenanigans/kernel.rb
67
+ - lib/shenanigans/README.mdown
68
+ - lib/shenanigans/string.rb
69
+ - lib/shenanigans/kernel/prompt.rb
70
+ - lib/shenanigans/kernel/fn.rb
71
+ - lib/shenanigans/kernel/with.rb
72
+ - lib/shenanigans/array.rb
73
+ - lib/shenanigans/array/zip_with.rb
64
74
  - lib/shenanigans/array/caret.rb
65
75
  - lib/shenanigans/array/random_subarray.rb
66
- - lib/shenanigans/array/zip_with.rb
67
- - lib/shenanigans/array.rb
68
- - lib/shenanigans/fixnum/string_length.rb
69
76
  - lib/shenanigans/fixnum.rb
70
- - lib/shenanigans/hash/extract.rb
71
77
  - lib/shenanigans/hash/has_shape_pred.rb
72
78
  - lib/shenanigans/hash/to_ostruct.rb
73
- - lib/shenanigans/hash.rb
74
- - lib/shenanigans/kernel/fn.rb
75
- - lib/shenanigans/kernel/prompt.rb
76
- - lib/shenanigans/kernel/with.rb
77
- - lib/shenanigans/kernel.rb
78
- - lib/shenanigans/object/display.rb
79
- - lib/shenanigans/object/it.rb
80
- - lib/shenanigans/object.rb
81
- - lib/shenanigans/README.mdown
79
+ - lib/shenanigans/hash/extract.rb
80
+ - lib/shenanigans/module.rb
81
+ - lib/shenanigans/module/private_accessor.rb
82
82
  - lib/shenanigans/string/in_groups_of.rb
83
- - lib/shenanigans/string.rb
84
- - lib/shenanigans.rb
85
- - test/array/test_caret.rb
86
- - test/array/test_random_subarray.rb
87
- - test/array/test_zip_with.rb
83
+ - lib/shenanigans/object/it.rb
84
+ - lib/shenanigans/object/display.rb
85
+ - lib/shenanigans/hash.rb
88
86
  - test/fixnum/test_string_length.rb
89
- - test/hash/test_extract.rb
90
- - test/hash/test_has_shape_pred.rb
91
- - test/hash/test_to_ostruct.rb
92
- - test/kernel/test_fn.rb
93
87
  - test/kernel/test_prompt.rb
94
88
  - test/kernel/test_with.rb
95
- - test/object/test_display.rb
96
- - test/object/test_it.rb
97
- - test/string/test_display.rb
89
+ - test/kernel/test_fn.rb
90
+ - test/array/test_zip_with.rb
91
+ - test/array/test_random_subarray.rb
92
+ - test/array/test_caret.rb
93
+ - test/hash/test_extract.rb
94
+ - test/hash/test_to_ostruct.rb
95
+ - test/hash/test_has_shape_pred.rb
96
+ - test/module/test_private_accessor.rb
98
97
  - test/string/test_in_groups_of.rb
98
+ - test/string/test_display.rb
99
+ - test/object/test_it.rb
100
+ - test/object/test_display.rb
99
101
  homepage: http://rubydoc.info/gems/shenanigans/frames
100
- licenses: []
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
101
105
  post_install_message:
102
106
  rdoc_options: []
103
107
  require_paths:
104
108
  - lib
105
109
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
110
  requirements:
108
- - - ! '>='
111
+ - - '>='
109
112
  - !ruby/object:Gem::Version
110
113
  version: '0'
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
115
  requirements:
114
- - - ! '>='
116
+ - - '>='
115
117
  - !ruby/object:Gem::Version
116
118
  version: '0'
117
119
  requirements: []
118
120
  rubyforge_project:
119
- rubygems_version: 1.8.23
121
+ rubygems_version: 2.0.3
120
122
  signing_key:
121
- specification_version: 3
123
+ specification_version: 4
122
124
  summary: Think Facets, just less useful
123
125
  test_files: []
124
- has_rdoc: