sleeping_king_studios-tools 0.7.0.rc.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +46 -5
  3. data/CODE_OF_CONDUCT.md +132 -0
  4. data/DEVELOPMENT.md +7 -16
  5. data/LICENSE +1 -1
  6. data/README.md +71 -145
  7. data/lib/sleeping_king_studios/tools.rb +12 -6
  8. data/lib/sleeping_king_studios/tools/array_tools.rb +86 -58
  9. data/lib/sleeping_king_studios/tools/base.rb +20 -0
  10. data/lib/sleeping_king_studios/tools/core_tools.rb +78 -19
  11. data/lib/sleeping_king_studios/tools/hash_tools.rb +69 -42
  12. data/lib/sleeping_king_studios/tools/integer_tools.rb +97 -55
  13. data/lib/sleeping_king_studios/tools/object_tools.rb +75 -52
  14. data/lib/sleeping_king_studios/tools/string_tools.rb +69 -96
  15. data/lib/sleeping_king_studios/tools/toolbelt.rb +44 -23
  16. data/lib/sleeping_king_studios/tools/toolbox.rb +2 -2
  17. data/lib/sleeping_king_studios/tools/toolbox/constant_map.rb +75 -74
  18. data/lib/sleeping_king_studios/tools/toolbox/inflector.rb +124 -0
  19. data/lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb +171 -0
  20. data/lib/sleeping_king_studios/tools/toolbox/mixin.rb +11 -11
  21. data/lib/sleeping_king_studios/tools/toolbox/semantic_version.rb +15 -14
  22. data/lib/sleeping_king_studios/tools/version.rb +15 -11
  23. metadata +105 -36
  24. data/lib/sleeping_king_studios/tools/all.rb +0 -5
  25. data/lib/sleeping_king_studios/tools/enumerable_tools.rb +0 -8
  26. data/lib/sleeping_king_studios/tools/semantic_version.rb +0 -15
  27. data/lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb +0 -185
  28. data/lib/sleeping_king_studios/tools/toolbox/configuration.rb +0 -207
  29. data/lib/sleeping_king_studios/tools/toolbox/delegator.rb +0 -175
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 62b15199f9c5de17132b5e6cd3e47f426385f0da
4
- data.tar.gz: a9eb228c33889f8bc4280a33deab36722bc287c2
2
+ SHA256:
3
+ metadata.gz: b185f72aa8d793ad425987881f1a1df9a37f2a4d2778775258ffb01ee2ec6d20
4
+ data.tar.gz: bdd496ed87a5fc539bdf25b33f7e9af22bb1f25a6f086b3fb29aad356591fb6a
5
5
  SHA512:
6
- metadata.gz: 33ac337400c83d57d375e53b767daf48f679648def7aa418f38cbec1d919ef6429a7523120ec003961c358279a10362959f815081bc6e414e1c117e4718b86b5
7
- data.tar.gz: a0040c5da758d70204c4ddab2012f90e6a7dc568c2d2bd797a267beb6b82079fe24822d403f16c5b6bd2ccff91ecda14821ab634d155362a7c0ce6bd5c44dd77
6
+ metadata.gz: e9a2cb6b86a351b4932119e60ac3f0688753183e3c6ae07ca485b105a80b0c64f7f3b75b94984b22add91b8b8ad7c1d83b4e54e57099c8f4d11d2acb1e7a2202
7
+ data.tar.gz: 4e4ae31ab84ee0ad8e85d2397ec7af1085c6d2a16932ad24ca15fdbd35936f094673012672b457eeac2d76c17849a9ea19eeccb9deef58a7e86821aff9603fe0
@@ -1,6 +1,51 @@
1
1
  # Changelog
2
2
 
3
- ## Upcoming Release
3
+ ### 1.0.0
4
+
5
+ - Removed all deprecated code from pre-1.0 releases.
6
+
7
+ #### Toolbox
8
+
9
+ Added some Hash-like methods to ConstantMap - `#each_key`, `#each_value`,
10
+ `#keys`, `#to_h`, and `#values`.
11
+
12
+ ### 0.8.0
13
+
14
+ Last minor release before 1.0.0.
15
+
16
+ This release adds a number of deprecations. All deprecated code will be removed
17
+ in version 1.0.0. Update dependent code accordingly.
18
+
19
+ - Removed deprecated SleepingKingStudios::Tools::SemanticVersion. This
20
+ functionality is still available as
21
+ SleepingKingStudios::Tools::Toolbox::SemanticVersion.
22
+
23
+ #### Tools
24
+
25
+ - Refactored all Tools modules to classes.
26
+ - Removed StringTools::PluralInflector. It's functionality is now handled by
27
+ Toolbox::Inflector.
28
+ - Added support for deprecation strategy to CoreTools#deprecate.
29
+
30
+ #### Toolbelt
31
+
32
+ - Refactored Toolbelt to reference Tools instances rather than classes.
33
+ - Defined new abbreviated helpers #ary, #hsh, #int, #obj, #str.
34
+ - Defined new helpers #array_tools, #core_tools, #hash_tools, #integer_tools,
35
+ #object_tools, #string_tools.
36
+ - Deprecated old abbreviated helpers #array, #core, #hash, #integer, #object,
37
+ #string.
38
+
39
+ #### Toolbox
40
+
41
+ - Deprecate Toolbox::Configuration. Use a struct instead.
42
+ - Deprecate Toolbox::Delegator. Use the stdlib Forwardable module instead.
43
+ - Implement Toolbox::Inflector, which serves as a delegate for StringTools.
44
+
45
+ ### 0.7.1
46
+
47
+ - Implement CoreTools#empty_binding.
48
+ - Implement HashTools#generate_binding.
4
49
 
5
50
  ### 0.7.0
6
51
 
@@ -20,8 +65,6 @@
20
65
  - IntegerTools#pluralize now accepts 2..3 arguments, and will automatically generate the plural string using StringTools#pluralize if an explicit plural is not given.
21
66
  - SleepingKingStudios::Tools::Toolbelt is now autoloaded from SleepingKingStudios::Tools.
22
67
 
23
- ## Current Release
24
-
25
68
  ### 0.6.0
26
69
 
27
70
  - Implement HashTools#convert_keys_to_strings and #convert_keys_to_symbols.
@@ -77,8 +120,6 @@ Implement ArrayTools#bisect and ArrayTools#splice.
77
120
 
78
121
  Implement #underscore.
79
122
 
80
- ## Previous Releases
81
-
82
123
  ### 0.2.0
83
124
 
84
125
  Split EnumerableTools into ArrayTools and HashTools.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ merlin@sleepingkingstudios.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126
+ at [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
@@ -1,26 +1,17 @@
1
1
  # Development Notes
2
2
 
3
- ## 0.7.0
4
-
5
3
  ## Future Tasks
6
4
 
7
- - Remove 'extend self' from Tools modules.
8
-
9
- ### Features
10
-
11
- - HashTools::slice, ::bisect_keys
12
- - ObjectTools::apply_with_arity
13
- - ObjectTools::method_arity
14
- - Delegator#delegate, :prefix => prefix_name
15
-
16
- #### Tools
5
+ ### Tools
17
6
 
7
+ - HashTools#bisect_keys
8
+ - HashTools#slice
9
+ - ObjectTools#apply_with_arity
10
+ - ObjectTools#method_arity
18
11
  - ObjectTools#pretty - returns user-friendly string representation. :multiline option? Delegates to specific toolset implementations.
19
12
  - RegexpTools#matching_string - generates a string that matches the regular expression. Does not support advanced Regexp features.
20
13
  - RegexpTools#nonmatching_strings - generates a set of strings that do not match the regular expression.
21
- - Identity Methods
22
- - RegexpTools#regexp? - true if object is regular expression, otherwise false.
23
14
 
24
- ### Maintenance
15
+ #### Identity Methods
25
16
 
26
- - Remove deprecated StringTools#pluralize(int, str, str) implementation.
17
+ - RegexpTools#regexp? - true if object is regular expression, otherwise false.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2013-2016 Rob Smith
3
+ Copyright (c) 2013 Rob Smith
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,13 +2,27 @@
2
2
 
3
3
  A library of utility services and concerns to expand the functionality of core classes without polluting the global namespace.
4
4
 
5
- ## Contribute
5
+ ## About
6
6
 
7
- - https://github.com/sleepingkingstudios/sleeping_king_studios-tools
7
+ SleepingKingStudios::Tools is tested against MRI Ruby 2.5 through 3.0.
8
8
 
9
- ### A Note From The Developer
9
+ ### Documentation
10
10
 
11
- Hi, I'm Rob Smith, a Ruby Engineer and the developer of this library. I use these tools every day, but they're not just written for me. If you find this project helpful in your own work, or if you have any questions, suggestions or critiques, please feel free to get in touch! I can be reached on GitHub (see above, and feel encouraged to submit bug reports or merge requests there) or via email at `merlin@sleepingkingstudios.com`. I look forward to hearing from you!
11
+ Method and class documentation is available courtesy of RubyDoc.
12
+
13
+ Documentation is generated using [YARD](https://yardoc.org/), and can be generated locally using the `yard` gem.
14
+
15
+ ### License
16
+
17
+ SleepingKingStudios::Tools is released under the [MIT License](https://opensource.org/licenses/MIT).
18
+
19
+ ### Contribute
20
+
21
+ The canonical repository for this gem is on [GitHub](https://github.com/sleepingkingstudios/sleeping_king_studios-tasks). Community contributions are welcome - please feel free to fork or submit issues, bug reports or pull requests.
22
+
23
+ ### Code of Conduct
24
+
25
+ Please note that the `SleepingKingStudios::Tools` project is released with a [Contributor Code of Conduct](https://github.com/sleepingkingstudios/sleeping_king_studios-tools/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.
12
26
 
13
27
  ## Tools
14
28
 
@@ -187,6 +201,14 @@ Prints a deprecation warning.
187
201
  ObjectTools#old_method was deprecated in version 0.1.0.
188
202
  called from /path/to/file.rb:4: in something_or_other
189
203
 
204
+ #### `#empty_binding`
205
+
206
+ Generates an empty Binding object. Note that this binding object still has
207
+ access to Object methods and constants - it is **not** eval-safe.
208
+
209
+ CoreTools.empty_binding
210
+ #=> Binding
211
+
190
212
  #### `#require_each`
191
213
 
192
214
  Takes a file pattern or a list of file names and requires each file.
@@ -262,6 +284,22 @@ Freezes the hash and performs a deep freeze on each hash key and value.
262
284
  hsh[:one].frozen?
263
285
  #=> true
264
286
 
287
+ #### `#generate_binding`
288
+
289
+ Generates a Binding object, with the hash converted to local variables in the
290
+ binding.
291
+
292
+ hsh = { :one => 'one', :two => 'two', :three => 'three' }
293
+ binding = HashTools.generate_binding(hsh)
294
+ #=> Binding
295
+
296
+ binding.local_variable_defined?(:one)
297
+ #=> true
298
+ binding.local_variable_get(:one)
299
+ #=> 'one'
300
+ binding.eval('one')
301
+ #=> 'one'
302
+
265
303
  #### `#hash?`
266
304
 
267
305
  Returns true if the object is or appears to be a Hash.
@@ -394,19 +432,19 @@ Creates a deep copy of the object. If the object is an Array, returns a new Arra
394
432
  :name => 'Welcome to the Jungle',
395
433
  :artist => "Guns N' Roses",
396
434
  :album => 'Appetite for Destruction'
397
- }, # end hash
435
+ },
398
436
  {
399
437
  :name => 'Hells Bells',
400
438
  :artist => 'AC/DC',
401
439
  :album => 'Back in Black'
402
- }, # end hash
440
+ },
403
441
  {
404
442
  :name => "Knockin' on Heaven's Door",
405
443
  :artist => 'Bob Dylan',
406
444
  :album => 'Pat Garrett & Billy The Kid'
407
- } # end hash
408
- ] # end array
409
- } # end hash
445
+ }
446
+ ]
447
+ }
410
448
 
411
449
  copy = ObjectTools.deep_dup data
412
450
 
@@ -428,19 +466,19 @@ Performs a deep freeze of the object. If the object is an Array, freezes the arr
428
466
  :name => 'Welcome to the Jungle',
429
467
  :artist => "Guns N' Roses",
430
468
  :album => 'Appetite for Destruction'
431
- }, # end hash
469
+ },
432
470
  {
433
471
  :name => 'Hells Bells',
434
472
  :artist => 'AC/DC',
435
473
  :album => 'Back in Black'
436
- }, # end hash
474
+ },
437
475
  {
438
476
  :name => "Knockin' on Heaven's Door",
439
477
  :artist => 'Bob Dylan',
440
478
  :album => 'Pat Garrett & Billy The Kid'
441
- } # end hash
442
- ] # end array
443
- } # end hash
479
+ }
480
+ ]
481
+ }
444
482
  ObjectTools.deep_freeze(data)
445
483
 
446
484
  data.frozen?
@@ -553,7 +591,7 @@ Adds the specified number of spaces to the start of each line of the string. Def
553
591
  "The Fellowship of the Ring",
554
592
  "The Two Towers",
555
593
  "The Return of the King"
556
- ] # end titles
594
+ ]
557
595
  string = titles.join "\n"
558
596
  StringTools.indent(string, 4)
559
597
  #=> " The Fellowship of the Ring\n"\
@@ -572,7 +610,7 @@ Yields each line of the string to the provided block and combines the results in
572
610
  "The Fellowship of the Ring",
573
611
  "The Two Towers",
574
612
  "The Return of the King"
575
- ] # end titles
613
+ ]
576
614
  string = titles.join "\n"
577
615
  StringTools.map_lines(string) { |line, index| "#{index}. #{line}" }
578
616
  #=> "0. The Fellowship of the Ring\n"\
@@ -667,73 +705,6 @@ Converts a mixed-case string expression to a lowercase, underscore separated str
667
705
 
668
706
  Common objects or patterns that are useful across projects but are larger than or do not fit the functional paradigm of the tools.* pattern.
669
707
 
670
- ### Configuration
671
-
672
- require 'sleeping_king_studios/tools/toolbox/configuration'
673
-
674
- Provides a simple DSL for defining configuration objects, which can be populated via hashes or data objects (such as a Rails configuration object).
675
-
676
- class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
677
- option :template_dir
678
-
679
- namespace :serialization do
680
- option :format, :default => :json, :enum => [:json, :xml, :yaml]
681
- end # namespace
682
- end # class
683
-
684
- # Initialize with a hash.
685
- hsh = YAML.load(File.read 'path/to/config.yml')
686
- config = MyGemConfig.new(hsh)
687
-
688
- # Initialize with a data object.
689
- klass = Struct.new(:template_dir)
690
- data = klass.new('path/to/templates')
691
- config = MyGemConfig.new(data)
692
-
693
- # Retrieve data by calling methods or using hash syntax. All of the
694
- # following will return the configured value:
695
- config.serialization.format
696
- config[:serialization][:format]
697
- config['serialization']['format']
698
- config.dig(:serialization, :format)
699
- config.fetch(:serialization', {}).fetch(:format, :json)
700
-
701
- #### `::namespace`
702
-
703
- Defines an inner namespace for the configuration, which will itself be an instance of Configuration. Can be nested to any depth:
704
-
705
- class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
706
- namespace :weapons do
707
- namespace :swords do
708
- namespace :upgrades do
709
- option :hilts
710
-
711
- option :tangs
712
- end # namespace
713
- end # namespace
714
- end # namespace
715
- end # class
716
-
717
- config.weapons.swords.upgrades
718
- #=> a Configuration instance, with options #hilts and #tangs.
719
-
720
- #### `::option`
721
-
722
- Defines an option, which creates an accessor and mutator method for the property. Can configure a :default (can be a value, a Proc, or the name of a
723
- method) and/or allowable values via the :enum option.
724
-
725
- class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
726
- option :max_level, :default => 20
727
-
728
- option :class, :enum => %(warrior ranger elementalist monk)
729
- end # class
730
-
731
- config.max_level
732
- # Returns 20 if no configured value is set.
733
-
734
- config.class = 'necromancer'
735
- # Raises an error.
736
-
737
708
  ### ConstantMap
738
709
 
739
710
  require 'sleeping_king_studios/tools/toolbox/constant_map'
@@ -741,10 +712,12 @@ method) and/or allowable values via the :enum option.
741
712
  Provides an enumerable interface for defining a group of constants.
742
713
 
743
714
  UserRoles = ConstantMap.new(
744
- :GUEST => 'guest',
745
- :USER => 'user',
746
- :ADMIN => 'admin'
747
- ) # end constants
715
+ {
716
+ GUEST: 'guest',
717
+ USER: 'user',
718
+ ADMIN: 'admin'
719
+ }'
720
+ )
748
721
 
749
722
  UserRoles::GUEST
750
723
  #=> 'guest'
@@ -755,74 +728,27 @@ Provides an enumerable interface for defining a group of constants.
755
728
  UserRoles.all
756
729
  #=> { :GUEST => 'guest', :USER => 'user', :ADMIN => 'admin' }
757
730
 
758
- ### Delegator
759
-
760
- require 'sleeping_king_studios/tools/toolbox/delegator'
731
+ ConstantMap includes `Enumerable`, with `#each` yielding the name and value of each defined constant. It also defines the following additional methods:
761
732
 
762
- Module for extending classes with basic delegation.
763
-
764
- class MyClass
765
- extend SleepingKingStudios::Tools::Toolbox::Delegator
766
-
767
- delegate :my_method, :to => MyService
768
- end # class
733
+ #### `#each_key`
769
734
 
770
- #### `::delegate`
735
+ Yields each defined constant name, similar to `Hash#each_key`.
771
736
 
772
- Defines a wrapper method to delegate implementation of the specified method or methods to an object, to the object at another specified method, or to the object at a specified instance variable.
737
+ #### `#each_value`
773
738
 
774
- # Delegate to an object
775
- class MyModule
776
- extend SleepingKingStudios::Tools::Toolbox::Delegator
739
+ Yields each defined constant value, similar to `Hash#each_value`.
777
740
 
778
- delegate :my_method, :to => MyService
779
- end class
741
+ #### `#keys`
780
742
 
781
- # Delegate to a method
782
- class MyModule
783
- extend SleepingKingStudios::Tools::Toolbox::Delegator
743
+ Returns an array containing the names of the defined constants, similar to `Hash#keys`.
784
744
 
785
- def my_service
786
- MyService.new
787
- end method my_service
745
+ #### `#to_h`
788
746
 
789
- delegate :my_method, :to => :my_service
790
- end class
791
-
792
- # Delegate to an instance variable
793
- class MyModule
794
- extend SleepingKingStudios::Tools::Toolbox::Delegator
795
-
796
- def initialize
797
- @my_service = MyService.new
798
- end constructor
799
-
800
- delegate :my_method, :to => :@my_service
801
- end class
802
-
803
- Expects one or more method names and a delegation target, which can be an object literal, or the name of an method or instance variable as a String or Symbol. Defines a wrapper method to delegate implementation of the specified method or methods to an object, to the object at the another specified method, or to the object at the specified instance variable.
804
-
805
- #### `::wrap_delegate`
806
-
807
- Wraps a delegate object by automatically delegating each method that is defined on the delegate class from the instance to the delegate. The delegate can be specified with an object literal or with the name of an instance method or instance variable.
808
-
809
- Only methods that are defined at the time #wrap_delegate is called will be delegated, so make sure to call #wrap_delegate after loading any gems or libraries that extend your delegate class, such as ActiveSupport.
810
-
811
- # Create a class that wraps a Hash
812
- class Errors
813
- extend SleepingKingStudios::Tools::Toolbox::Delegator
814
-
815
- wrap_delegate Hash.new { |hsh, key| hsh[key] = Errors.new }, :klass => Hash
816
-
817
- def messages
818
- @messages ||= []
819
- end # method messages
820
- end # class
747
+ Also `#all`. Returns a Hash representation of the constants.
821
748
 
822
- errors = Errors.new
823
- errors[:post].messages << "title can't be blank"
749
+ #### `#values`
824
750
 
825
- Expects a delegation target and optionally a class or module (to determine which methods to delegate), as well as optional :except and :only arrays to limit which methods are delegated. The delegation target can be an object literal, or the name of an method or instance variable as a String or Symbol (in which case a class or module must be specified in :klass or an ArgumentError will be raised).
751
+ Returns an array containing the values of the defined constants, similar to `Hash#values`.
826
752
 
827
753
  ### Mixin
828
754