Class: SerializedHashie::Extensions
- Inherits:
-
Object
- Object
- SerializedHashie::Extensions
- Defined in:
- lib/serialized_hashie/extensions.rb
Instance Method Summary collapse
- #add(name, &block) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize ⇒ Extensions
constructor
A new instance of Extensions.
- #reset ⇒ Object
- #run(value) ⇒ Object
Constructor Details
#initialize ⇒ Extensions
Returns a new instance of Extensions.
6 7 8 |
# File 'lib/serialized_hashie/extensions.rb', line 6 def initialize reset end |
Instance Method Details
#add(name, &block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/serialized_hashie/extensions.rb', line 14 def add(name, &block) if has?(name) raise Error, "Extension already defined named '#{name}'" end @extensions[name.to_sym] = block end |
#has?(name) ⇒ Boolean
22 23 24 |
# File 'lib/serialized_hashie/extensions.rb', line 22 def has?(name) @extensions.key?(name.to_sym) end |
#reset ⇒ Object
10 11 12 |
# File 'lib/serialized_hashie/extensions.rb', line 10 def reset @extensions = {} end |
#run(value) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/serialized_hashie/extensions.rb', line 26 def run(value) @extensions.each_value do |block| value = block.call(value) end value end |