1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

set accepts anything responding to each

Closes #8
This commit is contained in:
Simon Rozet 2010-07-11 11:11:18 +02:00
parent df9b786e59
commit 1187a86634
2 changed files with 7 additions and 2 deletions

View file

@ -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

View file

@ -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' }