lib/sinclair/options.rb in sinclair-1.6.4 vs lib/sinclair/options.rb in sinclair-1.6.5

- old
+ new

@@ -87,9 +87,33 @@ options.each do |key, value| instance_variable_set("@#{key}", value) end end + # Returns a hash with the current options + # + # @return [Hash] + # + # @example + # class ConnectionOptions < Sinclair::Options + # with_options :timeout, :retries, port: 443, protocol: 'https' + # end + # + # options = ConnectionOptions.new(retries: 10, port: 8080) + # + # options.to_h # returns + # # { + # # port: 8080, + # # retries: 10, + # # timeout: nil, + # # protocol: 'https' + # # } + def to_h + self.class.allowed_options.inject({}) do |hash, option| + hash.merge(option => public_send(option)) + end + end + # returns if other equals to self # # @param other [Object] object to be compared # # @return [TrueClass,FalseClass]