Skip to content

Commit

Permalink
check for Hash by checking for to_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Sep 23, 2012
1 parent 0458dbc commit 2e976ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/temple/mixins/engine_dsl.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def chain_name(name)
end end


def chain_class_constructor(filter, option_filter) def chain_class_constructor(filter, option_filter)
local_options = Hash === option_filter.last ? option_filter.pop : {} local_options = option_filter.last.respond_to?(:to_hash) ? option_filter.pop.to_hash : {}
raise(ArgumentError, 'Only symbols allowed in option filter') unless option_filter.all? {|o| Symbol === o } raise(ArgumentError, 'Only symbols allowed in option filter') unless option_filter.all? {|o| Symbol === o }
define_options(*option_filter) if respond_to?(:define_options) define_options(*option_filter) if respond_to?(:define_options)
proc do |engine| proc do |engine|
Expand Down
8 changes: 4 additions & 4 deletions lib/temple/mixins/options.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ def default_options
end end


def define_options(*opts) def define_options(*opts)
if opts.last.respond_to?(:keys) if opts.last.respond_to?(:to_hash)
hash = opts.pop hash = opts.pop.to_hash
default_options.add_valid_keys(hash.keys) default_options.add_valid_keys(hash.keys)
default_options.update(hash) default_options.update(hash)
end end
default_options.add_valid_keys(opts) default_options.add_valid_keys(opts)
end end


def define_deprecated_options(*opts) def define_deprecated_options(*opts)
if opts.last.respond_to?(:keys) if opts.last.respond_to?(:to_hash)
hash = opts.pop hash = opts.pop.to_hash
default_options.add_deprecated_keys(hash.keys) default_options.add_deprecated_keys(hash.keys)
default_options.update(hash) default_options.update(hash)
end end
Expand Down

0 comments on commit 2e976ae

Please sign in to comment.