Module: Fetchable
- Included in:
- Decorator
- Defined in:
- lib/fetchable.rb,
lib/fetchable/version.rb
Defined Under Namespace
Classes: Decorator
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
Instance Method Details
#fetch(key, not_found_value = no_default_given, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fetchable.rb', line 2 def fetch(key, not_found_value = no_default_given, &block) if not_found_value != no_default_given && block raise ArgumentError.new("Cannot provide both a default arg and block to #fetch") end result = public_send(:[], key) if result.nil? default_value(key, not_found_value, &block) else result end end |