Skip to content

Commit 0e8db6e

Browse files
committed
Fix arguments for Reader.for and Writer.for.
1 parent 08775a2 commit 0e8db6e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/rdf/reader.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ def self.each(&block)
8888
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
8989
#
9090
# @return [Class]
91-
def self.for(arg, &block)
91+
def self.for(*arg, &block)
92+
case arg.length
93+
when 0 then arg = nil
94+
when 1 then arg = arg.first
95+
else
96+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
97+
end
9298
arg = arg.merge(has_reader: true) if arg.is_a?(Hash)
9399
if format = self.format || Format.for(arg, &block)
94100
format.reader

lib/rdf/writer.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ def self.each(&block)
8989
# @return [Class]
9090
#
9191
# @return [Class]
92-
def self.for(options = {})
93-
options = options.merge(has_writer: true) if options.is_a?(Hash)
94-
if format = self.format || Format.for(options)
92+
def self.for(*arg, &block)
93+
case arg.length
94+
when 0 then arg = nil
95+
when 1 then arg = arg.first
96+
else
97+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
98+
end
99+
arg = arg.merge(has_writer: true) if arg.is_a?(Hash)
100+
if format = self.format || Format.for(arg)
95101
format.writer
96102
end
97103
end

0 commit comments

Comments
 (0)