Skip to content

Commit

Permalink
Enable inheriting from Parser without re-specifying @default options
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Fenton committed Nov 28, 2021
1 parent 300df33 commit 60c68de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/anystyle/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def instance
attr_reader :model, :options, :features, :normalizers, :mtime

def initialize(options = {})
@options = self.class.defaults.merge(options)
def_opts = self.class.defaults || Parser.defaults
@options = def_opts.merge(options)
load_model
end

Expand Down
7 changes: 7 additions & 0 deletions spec/anystyle/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,12 @@ module AnyStyle
end
end
end
describe "Inheritance" do
class ParserSubclass < AnyStyle::Parser
end
it 'Subclass can be initialized without own @defaults' do
expect { ParserSubclass.new }.not_to raise_error
end
end
end
end

0 comments on commit 60c68de

Please sign in to comment.