Sha256: 764fbf5a2678c5a74144246a8feaea3bb9e9e4ab28df8fcf62dad57c63f03ba7
Contents?: true
Size: 1.18 KB
Versions: 40
Compression:
Stored size: 1.18 KB
Contents
module Inch module API module Options class Base class << self # Creates an attribute with an optional default value # # @param name [Symbol] the name of the attribute # @param default [nil] the default value of the attribute # @return [void] def attribute(name, default = nil) define_method(name) do instance_variable_get("@#{name}") || default end @attributes ||= {} @attributes[to_s] ||= [] @attributes[to_s] << name end def attribute_names @attributes ||= {} @attributes[to_s] ||= [] end end def initialize(options_or_hash) self.class.attribute_names.each do |name| read options_or_hash, name end end protected def read(options_or_hash, name) value = if options_or_hash.is_a?(Hash) options_or_hash[name] else options_or_hash.send(name) end instance_variable_set("@#{name}", value) end end end end end
Version data entries
40 entries across 40 versions & 1 rubygems