lib/surrogate/endower.rb in surrogate-0.6.3 vs lib/surrogate/endower.rb in surrogate-0.6.4

- old
+ new

@@ -76,10 +76,31 @@ klass.instance_variable_set :@hatchery, Surrogate::Hatchery.new(klass, options) end def enable_defining_methods(klass) def klass.define(method_name, options={}, &block) - @hatchery.define method_name, options, &block + @hatchery.define method_name.to_sym, options, &block + end + + def klass.define_reader(*method_names, &block) + block ||= lambda {} + method_names.each { |method_name| define method_name, &block } + self + end + + def klass.define_writer(*method_names) + method_names.each do |method_name| + define "#{method_name}=" do |value| + instance_variable_set("@#{method_name}", value) + end + end + self + end + + def klass.define_accessor(*method_names, &block) + define_reader(*method_names, &block) + define_writer(*method_names) + self end end def enable_factory(klass, factory_name) return unless factory_name