Last active
December 23, 2015 18:19
-
-
Save cheald/6674718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.0.0p0 :012 > binding.pry | |
Frame number: 0/12 | |
[2] pry(main)> show-source d.find | |
From: enum.c (C Method): | |
Owner: Enumerable | |
Visibility: public | |
Number of lines: 18 | |
static VALUE | |
enum_find(int argc, VALUE *argv, VALUE obj) | |
{ | |
NODE *memo; | |
VALUE if_none; | |
rb_scan_args(argc, argv, "01", &if_none); | |
RETURN_ENUMERATOR(obj, argc, argv); | |
memo = NEW_MEMO(Qundef, 0, 0); | |
rb_block_call(obj, id_each, 0, 0, find_i, (VALUE)memo); | |
if (memo->u3.cnt) { | |
return memo->u1.value; | |
} | |
if (!NIL_P(if_none)) { | |
return rb_funcall(if_none, id_call, 0, 0); | |
} | |
return Qnil; | |
} | |
[3] pry(main)> d | |
=> #(Document:0x1dd33fc { | |
name = "document", | |
children = [ | |
#(DTD:0x1dd30b4 { name = "html" }), | |
#(Element:0x1dd2e48 { | |
name = "html", | |
children = [ | |
#(Element:0x1dd2c68 { | |
name = "body", | |
children = [ #(Element:0x1dd2a88 { name = "blockquote" })] | |
})] | |
})] | |
}) | |
[4] pry(main)> show-source d.xpath | |
From: /usr/local/rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.6.0/lib/nokogiri/xml/node.rb @ line 145: | |
Owner: Nokogiri::XML::Node | |
Visibility: public | |
Number of lines: 26 | |
def xpath *paths | |
return NodeSet.new(document) unless document | |
paths, handler, ns, binds = extract_params(paths) | |
sets = paths.map { |path| | |
ctx = XPathContext.new(self) | |
ctx.register_namespaces(ns) | |
path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml? | |
binds.each do |key,value| | |
ctx.register_variable key.to_s, value | |
end if binds | |
ctx.evaluate(path, handler) | |
} | |
return sets.first if sets.length == 1 | |
NodeSet.new(document) do |combined| | |
sets.each do |set| | |
set.each do |node| | |
combined << node | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment