Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/configurable/core_ext/extract_options.rb
Instance Method Summary collapse
-
#extractable_options? ⇒ Boolean
By default, only instances of Hash itself are extractable.
- #symbolize_keys ⇒ Object
-
#symbolize_keys! ⇒ Object
Destructively convert all keys to symbols, as long as they respond to
to_sym
. -
#to_args(box = true) ⇒ Object
Puts the hash into an array suitable for expanding into a parameter list, such that it will be interpreted as keyword parameters if the method you’re calling expects that.
Instance Method Details
#extractable_options? ⇒ Boolean
By default, only instances of Hash itself are extractable. Subclasses of Hash may implement this method and return true to declare themselves as extractable. If a Hash is extractable, Array#extract_options! pops it from the Array when it is the last element of the Array.
37 38 39 |
# File 'lib/configurable/core_ext/extract_options.rb', line 37 def instance_of?(Hash) end |
#symbolize_keys ⇒ Object
53 54 55 |
# File 'lib/configurable/core_ext/extract_options.rb', line 53 def symbolize_keys dup.symbolize_keys! end |
#symbolize_keys! ⇒ Object
Destructively convert all keys to symbols, as long as they respond to to_sym
.
46 47 48 49 50 51 |
# File 'lib/configurable/core_ext/extract_options.rb', line 46 def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key) || key] = delete(key) end self end |
#to_args(box = true) ⇒ Object
Puts the hash into an array suitable for expanding into a parameter list, such that it will be interpreted as keyword parameters if the method you’re calling expects that.
61 62 63 64 |
# File 'lib/configurable/core_ext/extract_options.rb', line 61 def to_args(box = true) args = self.symbolize_keys box ? [args] : args end |