lib/danica/operator/chained.rb in danica-2.0.5 vs lib/danica/operator/chained.rb in danica-2.0.6

- old
+ new

@@ -9,17 +9,34 @@ value = wrap_value(value) variables.include?(value) end def to_tex - variables.map(&:to_tex).join(" #{tex_symbol} ") + to_string(:tex) end def to_gnu - variables.map(&:to_gnu).join(" #{gnu_symbol} ") + to_string(:gnu) end private + + def to_string(type) + extractor = string_extractor("to_#{type}") + symbol = { tex: tex_symbol, gnu: gnu_symbol }[type] + variables.procedural_join(extractor, &join_proc(symbol)) + end + + def join_proc(symbol) + proc { " #{symbol} " } + end + + def string_extractor(method) + proc do |parcel| + parcel = wrap_as_group(parcel) + parcel.public_send(method) + end + end def repack(other) other_variables = other.is_a?(self.class) ? other.variables : [ other ] self.class.new(variables + other_variables) end