lib/configurable/delegate.rb in configurable-0.3.0 vs lib/configurable/delegate.rb in configurable-0.4.0

- old
+ new

@@ -25,12 +25,11 @@ # An hash of metadata for self, used to present the # delegate in different contexts (ex on the command # line, in a web form, or a desktop app). attr_reader :attributes - # Initializes a new Delegate with the specified key - # and default value. + # Initializes a new Delegate with the specified key and default value. def initialize(reader, writer="#{reader}=", default=nil, attributes={}) self.default = default self.reader = reader self.writer = writer @@ -59,19 +58,19 @@ # (see Delegate.duplicable_value?) def default(duplicate=true) duplicate && @duplicable ? @default.dup : @default end - # Sets the reader for self. The reader is symbolized, - # but may also be set to nil. + # Sets the reader for self. def reader=(value) - @reader = value == nil ? value : value.to_sym + raise ArgumentError, "reader may not be nil" if value == nil + @reader = value.to_sym end - # Sets the writer for self. The writer is symbolized, - # but may also be set to nil. + # Sets the writer for self. def writer=(value) - @writer = value == nil ? value : value.to_sym + raise ArgumentError, "writer may not be nil" if value == nil + @writer = value.to_sym end # Returns true if the default value is a kind of DelegateHash. def is_nest? @default.kind_of?(DelegateHash) \ No newline at end of file