class Sequel::SQL::Expression

  1. lib/sequel/extensions/eval_inspect.rb
Parent: SQL

Methods

Public Instance

  1. inspect

Public Instance methods

inspect ()

Attempt to produce a string suitable for eval, such that:

eval(obj.inspect) == obj
[show source]
# File lib/sequel/extensions/eval_inspect.rb, line 63
def inspect
  # Assume by default that the object can be recreated by calling
  # self.class.new with any attr_reader values defined on the class,
  # in the order they were defined.
  klass = self.class
  args = inspect_args.map do |arg|
    if arg.is_a?(String) && arg =~ /\A\*/
      # Special case string arguments starting with *, indicating that
      # they should return an array to be splatted as the remaining arguments
      send(arg.sub('*', '')).map{|a| Sequel.eval_inspect(a)}.join(', ')
    else
      Sequel.eval_inspect(send(arg))
    end
  end
  "#{klass}.new(#{args.join(', ')})"
end