Skip to content

Instantly share code, notes, and snippets.

@roy
Created January 23, 2014 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roy/73eff0cc6987634bd90c to your computer and use it in GitHub Desktop.
Save roy/73eff0cc6987634bd90c to your computer and use it in GitHub Desktop.
def to_s
inspect rescue super
end
def to_s
%x{
var val, el, str, result = [];
for (var i = 0, length = self.length; i < length; i++) {
el = self[i];
if (el == document) { return '#<Element [document]'; }
str = "<" + el.tagName.toLowerCase();
if (val = el.id) str += (' id="' + val + '"');
if (val = el.className) str += (' class="' + val + '"');
result.push(str + '>');
}
return '#<Element [' + result.join(', ') + ']>';
}
end
def inspect
%x{
var val, el, str, result = [];
for (var i = 0, length = self.length; i < length; i++) {
el = self[i];
str = "<" + el.tagName.toLowerCase();
if (val = el.id) str += (' id="' + val + '"');
if (val = el.className) str += (' class="' + val + '"');
result.push(str + '>');
}
return '#<Element [' + result.join(', ') + ']>';
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment