lib/rep.rb in rep-0.1.0 vs lib/rep.rb in rep-0.1.1
- old
+ new
@@ -117,11 +117,11 @@
# Defines an `#initialize` method that accepts a Hash argument and copies some keys out into `attr_accessors`.
# If your class already has an `#iniatialize` method then this will overwrite it (so don't use it). `#initialize_with`
# does not have to be used to use any other parts of Rep.
- def initialize_with(*args)
+ def initialize_with(*args, &blk)
@initializiation_args = args
# Remember what args we normally initialize with so we can refer to them when building shared instances.
if defined?(define_singleton_method)
@@ -135,19 +135,19 @@
# Create an `attr_accessor` for each one. Defaults can be provided using the Hash version { :arg => :default_value }
args.each { |a| register_accessor(a) }
- define_method(:initialize) { |*args|
- opts = args.first || {}
+ define_method(:initialize) { |opts={}|
parse_opts(opts)
}
# `#parse_opts` is responsable for getting the `attr_accessor` values prefilled. Since defaults can be specified, it
# must negotiate Hashes and use the first key of the hash for the `attr_accessor`'s name.
define_method :parse_opts do |opts|
@rep_options = opts
+ blk.call(opts) unless blk.nil?
self.class.initializiation_args.each do |field|
name = field.is_a?(Hash) ? field.to_a.first.first : field
instance_variable_set(:"@#{name}", opts[name])
end
end