lib/myrrha.rb in myrrha-1.2.1 vs lib/myrrha.rb in myrrha-1.2.2

- old
+ new

@@ -110,17 +110,18 @@ attr_accessor :main_target_domain # # Creates an empty list of coercion rules # - def initialize(upons = [], rules = [], fallbacks = [], main_target_domain = nil) - @upons = upons - @rules = rules - @fallbacks = fallbacks + def initialize(&defn) + @definitions = [] + @upons = [] + @rules = [] + @fallbacks = [] @appender = :<< - @main_target_domain = main_target_domain - yield(self) if block_given? + @main_target_domain = nil + extend_rules(:<<, defn) if defn end # # Appends the list of rules with new ones. # @@ -331,17 +332,22 @@ # be affected by any change made to the copy. # # @return [Coercions] a copy of this set of rules # def dup - Coercions.new(@upons.dup, @rules.dup, @fallbacks.dup, main_target_domain) + c = Coercions.new + @definitions.each do |defn| + c.extend_rules(*defn) + end + c end - private + protected # Extends existing rules def extend_rules(appender, block) + @definitions << [appender, block] @appender = appender block.call(self) self end @@ -380,6 +386,6 @@ OPTIONS[:core_ext] end end # module Myrrha require "myrrha/version" -require "myrrha/loader" \ No newline at end of file +require "myrrha/loader"