class ParsableHash::Strategies
Attributes
fallbacks[W]
Public Class Methods
fallbacks()
click to toggle source
# File lib/parsable_hash/strategies.rb, line 6 def fallbacks @fallbacks.nil? ? true : @fallbacks end
new(value = {})
click to toggle source
# File lib/parsable_hash/strategies.rb, line 13 def initialize(value = {}) strategies[:default] = value end
Public Instance Methods
[](strategy)
click to toggle source
# File lib/parsable_hash/strategies.rb, line 17 def [](strategy) get(strategy) end
[]=(strategy, value)
click to toggle source
# File lib/parsable_hash/strategies.rb, line 21 def []=(strategy, value) add(strategy, value) end
add(strategy, value)
click to toggle source
# File lib/parsable_hash/strategies.rb, line 34 def add(strategy, value) strategies[strategy] = value end
get(strategy)
click to toggle source
# File lib/parsable_hash/strategies.rb, line 25 def get(strategy) _strategy = strategies[strategy.to_sym] return _strategy unless _strategy.nil? return strategies[:default] if _strategy.nil? && self.class.fallbacks raise MissingStrategy.new("Strategy #{strategy} is missing!") end
Private Instance Methods
strategies()
click to toggle source
# File lib/parsable_hash/strategies.rb, line 40 def strategies @strategies ||= {} end