lib/hyperclient/resource.rb in hyperclient-0.7.0 vs lib/hyperclient/resource.rb in hyperclient-0.7.1
- old
+ new
@@ -55,9 +55,21 @@
def [](name)
send(name) if respond_to?(name)
end
+ def fetch(key, *args)
+ return self[key] if respond_to?(key)
+
+ if args.any?
+ args.first
+ elsif block_given?
+ yield key
+ else
+ fail KeyError
+ end
+ end
+
private
# Internal: Returns the self Link of the Resource. Used to handle the HTTP
# methods.
def _self_link