From 1187a866346e82c98b8ad545b8f155632f7d9283 Mon Sep 17 00:00:00 2001 From: Simon Rozet Date: Sun, 11 Jul 2010 11:11:18 +0200 Subject: [PATCH] set accepts anything responding to each Closes #8 --- lib/sinatra/base.rb | 4 ++-- test/settings_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index d0fac996..18859f6c 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -704,8 +704,8 @@ module Sinatra metadef(option, &value) metadef("#{option}?") { !!__send__(option) } metadef("#{option}=") { |val| metadef(option, &Proc.new{val}) } - elsif value == self && option.respond_to?(:to_hash) - option.to_hash.each { |k,v| set(k, v) } + elsif value == self && option.respond_to?(:each) + option.each { |k,v| set(k, v) } elsif respond_to?("#{option}=") __send__ "#{option}=", value else diff --git a/test/settings_test.rb b/test/settings_test.rb index 16f80296..e643a36e 100644 --- a/test/settings_test.rb +++ b/test/settings_test.rb @@ -43,6 +43,11 @@ class SettingsTest < Test::Unit::TestCase assert_equal 'bizzle', @base.baz end + it 'sets multiple settings using #each' do + @base.set [["foo", "bar"]] + assert_equal "bar", @base.foo + end + it 'inherits settings methods when subclassed' do @base.set :foo, 'bar' @base.set :biz, Proc.new { 'baz' }