Sha256: 1cab6743eccce69a3149599f275de1a75e4416eace433360cf3167fb25a1d77f

Contents?: true

Size: 608 Bytes

Versions: 3

Compression:

Stored size: 608 Bytes

Contents

class Object
  # Setup a default pretty_inspect
  # alias_method :pretty_inspect, :inspect

  def instance_values
    Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }]
  end

  def html_inspect
    inspect.gsub('<', '&lt;').gsub('>', '&gt;')
  end

  # TODO: Need a real implementation of this
  def deep_clone
    if RUBY_PLATFORM == 'opal'
      JSON.parse(to_json)
    else
      Marshal.load(Marshal.dump(self))
    end
  end

  def try(*a, &b)
    if a.empty? && block_given?
      yield self
    else
      public_send(*a, &b) if respond_to?(a.first)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.9.3.pre2 lib/volt/extra_core/object.rb
volt-0.9.3.pre1 lib/volt/extra_core/object.rb
volt-0.9.2 lib/volt/extra_core/object.rb