sleeping_king_studios-ext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a577560ebfa76eda2fb92e99731fd660d46ef67c
4
+ data.tar.gz: 08f133c3c52f49a36b977e42da1fd293d24dbaec
5
+ SHA512:
6
+ metadata.gz: 1abefaf6b82006133c1820a32f38939ca43836fa9a06aa3804ccae2f9f001a37f98f63f8e1292d256512007d7bbec32f3cf21e6b9a447d907bed914d068e1a03
7
+ data.tar.gz: 77753ec2b8bea81cc240e45d5c011f2f62e3a396925acd5c8b4e1ef4bba3a5f58318e37f1537e67ee430a1c6bbd6050bf83c5a3be80db17e539166d667364f75
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release version.
6
+
7
+ ### Array
8
+
9
+ - Added Array#fold method.
10
+
11
+ ### Object
12
+
13
+ - Added Object#metaclass method.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2013 Rob Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # SleepingKingStudios::Ext
2
+
3
+ A collection of extensions to core classes.
4
+
5
+ ## The Extensions
6
+
7
+ ### Array\#fold
8
+
9
+ require 'sleeping_king_studios/ext/array/fold'
10
+
11
+ Loops through the items in the array and counts the number of times each item
12
+ appears. If a block is provided, each item is passed into the block, and the
13
+ result of yielding the block is counted instead.
14
+
15
+ _Example:_ Find the number of times each item appears in the array.
16
+
17
+ items = %w(foo foo foo bar bar baz wibble wobble)
18
+ items.fold
19
+ #=> { 'foo' => 3, 'bar' => 2, 'baz' => 1, 'wibble' => 1, 'wobble' => 1 }
20
+
21
+ _Example:_ Count the items in the array with each status value.
22
+
23
+ class SampleItem < Struct.new(:status); end
24
+ items = [
25
+ SampleItem.new :approved,
26
+ SampleItem.new :rejected,
27
+ SampleItem.new :approved,
28
+ SampleItem.new :approved,
29
+ SampleItem.new :error,
30
+ SampleItem.new nil,
31
+ SampleItem.new :rejected,
32
+ ] # end array
33
+ items.fold { |item| item.status }
34
+ #=> { :approved => 3, :rejected => 2, :error => 1, nil => 1 }
35
+
36
+ ### Object\#metaclass
37
+
38
+ require 'sleeping_king_studios/ext/object/metaclass'
39
+
40
+ Returns the object's metaclass, a Class that holds any functionality specific
41
+ to that object instance, e.g. a method defined using
42
+ `Object#define_singleton_method`, or a module that the instance extends.
43
+
44
+ ## License
45
+
46
+ SleepingKingStudios::Ext is released under the
47
+ [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1,40 @@
1
+ # lib/sleeping_king_studios/ext/array/fold.rb
2
+
3
+ class Array
4
+ # Loops through the items in the array and counts the number of times each
5
+ # item appears. If a block is provided, each item is passed into the block,
6
+ # and the result of yielding the block is counted instead.
7
+ #
8
+ # @return [Hash] A hash whose keys are the items in the
9
+ # array or the results of yielding the block, and whose values are the
10
+ # number of times each item appeared in the array.
11
+ #
12
+ # @example Find the number of times each item appears in the array.
13
+ #
14
+ # items = %w(foo foo foo bar bar baz wibble wobble)
15
+ # items.fold
16
+ # #=> { 'foo' => 3, 'bar' => 2, 'baz' => 1, 'wibble' => 1, 'wobble' => 1 }
17
+ #
18
+ # @example Count the items in the array with each status value.
19
+ #
20
+ # class SampleItem < Struct.new(:status); end
21
+ # items = [
22
+ # SampleItem.new :approved,
23
+ # SampleItem.new :rejected,
24
+ # SampleItem.new :approved,
25
+ # SampleItem.new :approved,
26
+ # SampleItem.new :error,
27
+ # SampleItem.new nil,
28
+ # SampleItem.new :rejected,
29
+ # ] # end array
30
+ # items.fold { |item| item.status }
31
+ # #=> { :approved => 3, :rejected => 2, :error => 1, nil => 1 }
32
+ #
33
+ # @since 0.1.0
34
+ def fold
35
+ each.with_object({}) do |item, hsh|
36
+ value = block_given? ? yield(item) : item
37
+ hsh[value] = hsh.fetch(value, 0) + 1
38
+ end # each with object
39
+ end # method fold
40
+ end # class
@@ -0,0 +1,14 @@
1
+ # lib/sleeping_king_studios/ext/object/metaclass.rb
2
+
3
+ class Object
4
+ # Returns the object's metaclass, a Class that holds any functionality
5
+ # specific to that object instance, e.g. a method defined using
6
+ # Object#define_singleton_method, or a module that the instance extends.
7
+ #
8
+ # @return [Class] The object's metaclass.
9
+ #
10
+ # @since 0.1.0
11
+ def metaclass
12
+ class << self; self; end
13
+ end # method metaclass
14
+ end # class
@@ -0,0 +1,7 @@
1
+ # lib/sleeping_king_studios/ext/version.rb
2
+
3
+ module SleepingKingStudios
4
+ module Ext
5
+ VERSION = '0.1.0'
6
+ end # module
7
+ end # module
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sleeping_king_studios-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob "Merlin" Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fuubar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
55
+ description: |2
56
+ A collection of extensions to core classes, gemified to prevent a
57
+ maintenance nightmare if multiple library or application projects require
58
+ general extensions.
59
+ email:
60
+ - merlin@sleepingkingstudios.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/sleeping_king_studios/ext/array/fold.rb
66
+ - lib/sleeping_king_studios/ext/object/metaclass.rb
67
+ - lib/sleeping_king_studios/ext/version.rb
68
+ - LICENSE
69
+ - CHANGELOG.md
70
+ - README.md
71
+ homepage: http://sleepingkingstudios.com
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Extensions to core classes.
95
+ test_files: []
96
+ has_rdoc: