module LANSA::XML::Utils

Public Instance Methods

call_method(method, *args) click to toggle source

Helper method to call a method with the right “number” of arguments. Used to call ‘overloaded’ Transfomer methods like ‘intercept_start_element’ or ‘intercept_end_element’ where we have added non-standard args like ‘depth’ and ‘value’!

# File xml/transformer.rb, line 43
def call_method method, *args

  return nil unless method.is_a?(Method)
  arity = method.arity

  if arity >= 0 and arity < args.size
    # Only use as many args as defined in the method
    method.call(args[0, arity])
  else
    # Call method with all args, which will raise an exception,
    # if e.g. the number of method arguments does not match.
    method.call(*args)
  end

end
call_object_method(object, method_name, *args) click to toggle source

Helper method to call a method with the right “number” of arguments. Used to call ‘overloaded’ Transfomer methods like ‘intercept_start_element’ or ‘intercept_end_element’ where we have added non-standard args like ‘depth’ and ‘value’!

# File xml/transformer.rb, line 26
def call_object_method object, method_name, *args

  return nil if object.nil? or method_name.nil?

  method_name = method_name.to_s.to_sym unless method_name.is_a?(Symbol)
  return nil unless object.respond_to?(method_name)

  method = object.method(method_name)
  return call_method(method, *args)

end