Module: Dommy

Defined in:
lib/dommy/window.rb,
lib/dommy.rb,
lib/dommy/css.rb,
lib/dommy/url.rb,
lib/dommy/attr.rb,
lib/dommy/blob.rb,
lib/dommy/node.rb,
lib/dommy/event.rb,
lib/dommy/fetch.rb,
lib/dommy/range.rb,
lib/dommy/bridge.rb,
lib/dommy/crypto.rb,
lib/dommy/parser.rb,
lib/dommy/screen.rb,
lib/dommy/worker.rb,
lib/dommy/backend.rb,
lib/dommy/browser.rb,
lib/dommy/element.rb,
lib/dommy/history.rb,
lib/dommy/promise.rb,
lib/dommy/storage.rb,
lib/dommy/streams.rb,
lib/dommy/version.rb,
lib/dommy/data_uri.rb,
lib/dommy/document.rb,
lib/dommy/location.rb,
lib/dommy/animation.rb,
lib/dommy/form_data.rb,
lib/dommy/navigator.rb,
lib/dommy/resources.rb,
lib/dommy/scheduler.rb,
lib/dommy/dom_parser.rb,
lib/dommy/js/runtime.rb,
lib/dommy/navigation.rb,
lib/dommy/text_codec.rb,
lib/dommy/web_socket.rb,
lib/dommy/file_reader.rb,
lib/dommy/interaction.rb,
lib/dommy/performance.rb,
lib/dommy/shadow_root.rb,
lib/dommy/tree_walker.rb,
lib/dommy/url_pattern.rb,
lib/dommy/cookie_store.rb,
lib/dommy/event_source.rb,
lib/dommy/js/wire_tags.rb,
lib/dommy/notification.rb,
lib/dommy/svg_elements.rb,
lib/dommy/test_helpers.rb,
lib/dommy/data_transfer.rb,
lib/dommy/dom_exception.rb,
lib/dommy/html_elements.rb,
lib/dommy/html_elements.rb,
lib/dommy/internal/idna.rb,
lib/dommy/js/import_map.rb,
lib/dommy/js/marshaller.rb,
lib/dommy/bridge/methods.rb,
lib/dommy/js/host_bridge.rb,
lib/dommy/js/script_boot.rb,
lib/dommy/rspec/matchers.rb,
lib/dommy/custom_elements.rb,
lib/dommy/html_collection.rb,
lib/dommy/js/handle_table.rb,
lib/dommy/message_channel.rb,
lib/dommy/resize_observer.rb,
lib/dommy/callable_invoker.rb,
lib/dommy/js/module_loader.rb,
lib/dommy/media_query_list.rb,
lib/dommy/xml_http_request.rb,
lib/dommy/deferred_response.rb,
lib/dommy/interaction/debug.rb,
lib/dommy/internal/css/calc.rb,
lib/dommy/internal/punycode.rb,
lib/dommy/js/dom_interfaces.rb,
lib/dommy/mutation_observer.rb,
lib/dommy/interaction/driver.rb,
lib/dommy/internal/aria_role.rb,
lib/dommy/internal/css/color.rb,
lib/dommy/internal/idna_data.rb,
lib/dommy/compression_streams.rb,
lib/dommy/html_canvas_element.rb,
lib/dommy/interaction/locator.rb,
lib/dommy/internal/aria_state.rb,
lib/dommy/internal/child_node.rb,
lib/dommy/internal/cookie_jar.rb,
lib/dommy/internal/css/parser.rb,
lib/dommy/internal/namespaces.rb,
lib/dommy/internal/url_parser.rb,
lib/dommy/minitest/assertions.rb,
lib/dommy/internal/css/cascade.rb,
lib/dommy/internal/ipv4_parser.rb,
lib/dommy/internal/parent_node.rb,
lib/dommy/performance_observer.rb,
lib/dommy/internal/css/counters.rb,
lib/dommy/internal/css/supports.rb,
lib/dommy/internal/dom_matching.rb,
lib/dommy/internal/selector_ast.rb,
lib/dommy/intersection_observer.rb,
lib/dommy/js/bridge_conformance.rb,
lib/dommy/backend/makiri_adapter.rb,
lib/dommy/interaction/role_query.rb,
lib/dommy/internal/aria_snapshot.rb,
lib/dommy/internal/css_rule_text.rb,
lib/dommy/internal/node_equality.rb,
lib/dommy/interaction/dom_summary.rb,
lib/dommy/internal/css/rule_index.rb,
lib/dommy/internal/node_traversal.rb,
lib/dommy/internal/selector_index.rb,
lib/dommy/js/constructor_resolver.rb,
lib/dommy/internal/accessible_name.rb,
lib/dommy/internal/css/media_query.rb,
lib/dommy/internal/selector_parser.rb,
lib/dommy/js/custom_element_bridge.rb,
lib/dommy/internal/element_matching.rb,
lib/dommy/internal/global_functions.rb,
lib/dommy/internal/observer_manager.rb,
lib/dommy/internal/observer_matcher.rb,
lib/dommy/internal/scope_resolution.rb,
lib/dommy/internal/selector_matcher.rb,
lib/dommy/rspec/capy_style_matchers.rb,
lib/dommy/internal/css/ua_stylesheet.rb,
lib/dommy/internal/xml_serialization.rb,
lib/dommy/bridge/constructor_registry.rb,
lib/dommy/interaction/event_synthesis.rb,
lib/dommy/interaction/form_submission.rb,
lib/dommy/internal/accessibility_tree.rb,
lib/dommy/internal/node_wrapper_cache.rb,
lib/dommy/interaction/field_interactor.rb,
lib/dommy/internal/css_pseudo_handlers.rb,
lib/dommy/internal/observable_callback.rb,
lib/dommy/internal/mutation_coordinator.rb,
lib/dommy/internal/reflected_attributes.rb,
lib/dommy/internal/shadow_root_registry.rb,
lib/dommy/internal/css/custom_properties.rb,
lib/dommy/internal/css/property_registry.rb,
lib/dommy/internal/range_text_serializer.rb,
lib/dommy/internal/accessible_description.rb,
lib/dommy/internal/template_content_registry.rb,
lib/dommy/internal/css/computed_style_declaration.rb

Overview

Generated by script/build_idna_tables.rb from Unicode 16.0.0 source files in vendor/unicode/. Re-run after upgrading.

Tables are sorted, non-overlapping [start, end, value...] rows. IDNAData.lookup(table, cp) does a binary search and returns the matching row (or nil).

Defined Under Namespace

Modules: Backend, Bridge, CallableInvoker, DataUri, EventTarget, HyperlinkActivation, Interaction, Internal, Js, Minitest, Navigation, Node, NodeFilter, Parser, RSpec, Resources, SubmitButtonActivation, TestHelpers, TreeTraversalCore, WindowReflectingHandlers Classes: AbortController, AbortSignal, Animation, Attr, BatteryManager, BeforeUnloadEvent, Blob, BroadcastChannel, Browser, CDATASectionNode, CSSNamespace, CSSRule, CSSRuleList, CSSStyleSheet, CanvasGradient, CanvasRenderingContext2D, CharacterDataNode, ClassList, Clipboard, ClipboardEvent, CloseEvent, CommentNode, CompositionEvent, CompressionStream, CookieChangeEvent, CookieStore, Crypto, CryptoKey, CustomElementRegistry, CustomEvent, DOMException, DOMImplementation, DOMParser, DOMRect, DataTransfer, DatasetMap, DecompressionStream, DeferredResponse, Document, DocumentType, DragEvent, Element, ErrorEvent, ErrorValue, Event, EventSource, FetchFn, File, FileList, FileReader, FocusEvent, FormData, Fragment, Geolocation, HTMLAnchorElement, HTMLAreaElement, HTMLAudioElement, HTMLBRElement, HTMLBaseElement, HTMLBodyElement, HTMLButtonElement, HTMLCanvasElement, HTMLCollection, HTMLDListElement, HTMLDataElement, HTMLDataListElement, HTMLDetailsElement, HTMLDialogElement, HTMLDirectoryElement, HTMLDivElement, HTMLElement, HTMLEmbedElement, HTMLFieldSetElement, HTMLFontElement, HTMLFormControlsCollection, HTMLFormElement, HTMLFrameElement, HTMLFrameSetElement, HTMLHRElement, HTMLHeadElement, HTMLHeadingElement, HTMLHtmlElement, HTMLIFrameElement, HTMLImageElement, HTMLInputElement, HTMLLIElement, HTMLLabelElement, HTMLLegendElement, HTMLLinkElement, HTMLMapElement, HTMLMediaElement, HTMLMetaElement, HTMLMeterElement, HTMLModElement, HTMLOListElement, HTMLObjectElement, HTMLOptGroupElement, HTMLOptionElement, HTMLOptionsCollection, HTMLOutputElement, HTMLParagraphElement, HTMLParamElement, HTMLPictureElement, HTMLPreElement, HTMLProgressElement, HTMLQuoteElement, HTMLScriptElement, HTMLSelectElement, HTMLSlotElement, HTMLSourceElement, HTMLSpanElement, HTMLStyleElement, HTMLTableCaptionElement, HTMLTableCellElement, HTMLTableColElement, HTMLTableElement, HTMLTableRowElement, HTMLTableSectionElement, HTMLTemplateElement, HTMLTextAreaElement, HTMLTimeElement, HTMLTitleElement, HTMLTrackElement, HTMLUListElement, HTMLUnknownElement, HTMLVideoElement, HashChangeEvent, Headers, History, ImageData, InputEvent, IntersectionObserver, KeyboardEvent, KeyframeEffect, LiveNodeList, Location, Lock, LockManager, MediaList, MediaQueryList, MediaQueryListEvent, MessageChannel, MessageEvent, MessagePort, MouseEvent, MutationObserver, MutationRecord, NamedNodeMap, Navigator, NodeIterator, NodeList, Notification, Performance, PerformanceEntry, PerformanceObserver, PermissionStatus, Permissions, PointerEvent, PopStateEvent, ProcessingInstructionNode, ProgressEvent, PromiseRejectionEvent, PromiseValue, RadioNodeList, Range, ReadableStream, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, ResizeObserver, Response, RuleStyleDeclaration, SVGAElement, SVGAnimateElement, SVGAnimateMotionElement, SVGAnimateTransformElement, SVGAnimationElement, SVGCircleElement, SVGClipPathElement, SVGComponentTransferFunctionElement, SVGDefsElement, SVGDescElement, SVGDiscardElement, SVGElement, SVGEllipseElement, SVGFEBlendElement, SVGFEColorMatrixElement, SVGFEComponentTransferElement, SVGFECompositeElement, SVGFEConvolveMatrixElement, SVGFEDiffuseLightingElement, SVGFEDisplacementMapElement, SVGFEDistantLightElement, SVGFEDropShadowElement, SVGFEFloodElement, SVGFEFuncAElement, SVGFEFuncBElement, SVGFEFuncGElement, SVGFEFuncRElement, SVGFEGaussianBlurElement, SVGFEImageElement, SVGFEMergeElement, SVGFEMergeNodeElement, SVGFEMorphologyElement, SVGFEOffsetElement, SVGFEPointLightElement, SVGFESpecularLightingElement, SVGFESpotLightElement, SVGFETileElement, SVGFETurbulenceElement, SVGFilterElement, SVGFilterPrimitiveElement, SVGForeignObjectElement, SVGGElement, SVGImageElement, SVGLineElement, SVGLinearGradientElement, SVGMPathElement, SVGMarkerElement, SVGMaskElement, SVGMetadataElement, SVGPathElement, SVGPatternElement, SVGPolygonElement, SVGPolylineElement, SVGRadialGradientElement, SVGRectElement, SVGSVGElement, SVGSetElement, SVGStopElement, SVGSwitchElement, SVGSymbolElement, SVGTSpanElement, SVGTextElement, SVGTextPathElement, SVGTitleElement, SVGUseElement, SVGViewElement, Scheduler, Screen, ScreenOrientation, Selection, ShadowRoot, StandaloneEventTarget, Storage, StorageManager, StyleDeclaration, SubmitEvent, SubtleCrypto, TextDecoder, TextDecoderStream, TextEncoder, TextEncoderStream, TextMetrics, TextNode, ToggleEvent, Touch, TouchEvent, TouchList, TransformStream, TransformStreamDefaultController, TreeWalker, UIEvent, URL, URLPattern, URLSearchParams, ValidityState, ViewTransition, WakeLock, WakeLockSentinel, WebSocket, WheelEvent, Window, Worker, WritableStream, WritableStreamDefaultWriter, XMLHttpRequest, XMLHttpRequestUpload, XMLSerializer

Constant Summary collapse

VERSION =
"0.10.0"
SVG_ELEMENT_CLASSES =

Tag-name → class lookup. Keys are the lowercased form Nokogiri::HTML5 stores in the tree. Tags absent from this table fall through to Dommy::SVGElement via element_class_for.

{
  "svg" => SVGSVGElement,
  "g" => SVGGElement,
  "circle" => SVGCircleElement,
  "rect" => SVGRectElement,
  "ellipse" => SVGEllipseElement,
  "line" => SVGLineElement,
  "polygon" => SVGPolygonElement,
  "polyline" => SVGPolylineElement,
  "path" => SVGPathElement,
  "text" => SVGTextElement,
  "tspan" => SVGTSpanElement,
  "defs" => SVGDefsElement,
  "use" => SVGUseElement,
  "image" => SVGImageElement,
  "symbol" => SVGSymbolElement,
  "foreignobject" => SVGForeignObjectElement,
  "title" => SVGTitleElement,
  "desc" => SVGDescElement,
  "mask" => SVGMaskElement,
  "clippath" => SVGClipPathElement,
  "pattern" => SVGPatternElement,
  "lineargradient" => SVGLinearGradientElement,
  "radialgradient" => SVGRadialGradientElement,
  "stop" => SVGStopElement,
  "filter" => SVGFilterElement,
  "marker" => SVGMarkerElement,

  # Recommended additions
  "a" => SVGAElement,
  "textpath" => SVGTextPathElement,
  "view" => SVGViewElement,
  "switch" => SVGSwitchElement,
  "metadata" => SVGMetadataElement,

  # Filter primitives (common ones)
  "fegaussianblur" => SVGFEGaussianBlurElement,
  "feoffset" => SVGFEOffsetElement,
  "feblend" => SVGFEBlendElement,
  "fecolormatrix" => SVGFEColorMatrixElement,
  "feflood" => SVGFEFloodElement,
  "fecomposite" => SVGFECompositeElement,
  "femerge" => SVGFEMergeElement,
  "femergenode" => SVGFEMergeNodeElement,
  "fecomponenttransfer" => SVGFEComponentTransferElement,
  "fefuncr" => SVGFEFuncRElement,
  "fefuncg" => SVGFEFuncGElement,
  "fefuncb" => SVGFEFuncBElement,
  "fefunca" => SVGFEFuncAElement,
  "fetile" => SVGFETileElement,
  "femorphology" => SVGFEMorphologyElement,
  "feimage" => SVGFEImageElement,
  "fedropshadow" => SVGFEDropShadowElement,
  "feturbulence" => SVGFETurbulenceElement,
  "fedisplacementmap" => SVGFEDisplacementMapElement,
  "fedistantlight" => SVGFEDistantLightElement,
  "fepointlight" => SVGFEPointLightElement,
  "fespotlight" => SVGFESpotLightElement,
  "feconvolvematrix" => SVGFEConvolveMatrixElement,
  "fediffuselighting" => SVGFEDiffuseLightingElement,
  "fespecularlighting" => SVGFESpecularLightingElement,

  # SMIL animation
  "animate" => SVGAnimateElement,
  "animatetransform" => SVGAnimateTransformElement,
  "animatemotion" => SVGAnimateMotionElement,
  "set" => SVGSetElement,
  "mpath" => SVGMPathElement,
  "discard" => SVGDiscardElement
}.freeze
HTML_ELEMENT_CLASSES =

Look up the subclass for a given HTML tag. Document#wrap_node consults this map; defaults to plain Element.

{
  "a" => HTMLAnchorElement,
  "form" => HTMLFormElement,
  "input" => HTMLInputElement,
  "button" => HTMLButtonElement,
  "img" => HTMLImageElement,
  "canvas" => HTMLCanvasElement,
  "script" => HTMLScriptElement,
  "link" => HTMLLinkElement,
  "select" => HTMLSelectElement,
  "option" => HTMLOptionElement,
  "optgroup" => HTMLOptGroupElement,
  "textarea" => HTMLTextAreaElement,
  "label" => HTMLLabelElement,
  "fieldset" => HTMLFieldSetElement,
  "output" => HTMLOutputElement,
  "legend" => HTMLLegendElement,
  "slot" => HTMLSlotElement,
  "table" => HTMLTableElement,
  "thead" => HTMLTableSectionElement,
  "tbody" => HTMLTableSectionElement,
  "tfoot" => HTMLTableSectionElement,
  "tr" => HTMLTableRowElement,
  "td" => HTMLTableCellElement,
  "th" => HTMLTableCellElement,
  "caption" => HTMLTableCaptionElement,
  "dialog" => HTMLDialogElement,
  "details" => HTMLDetailsElement,
  "meter" => HTMLMeterElement,
  "progress" => HTMLProgressElement,
  "template" => HTMLTemplateElement,
  "audio" => HTMLAudioElement,
  "video" => HTMLVideoElement,
  "source" => HTMLSourceElement,
  "track" => HTMLTrackElement,
  "iframe" => HTMLIFrameElement,
  "picture" => HTMLPictureElement,
  "ol" => HTMLOListElement,
  "ul" => HTMLUListElement,
  "li" => HTMLLIElement,
  "time" => HTMLTimeElement,
  "data" => HTMLDataElement,
  "area" => HTMLAreaElement,
  "map" => HTMLMapElement,
  "object" => HTMLObjectElement,
  "embed" => HTMLEmbedElement,
  "base" => HTMLBaseElement,
  "meta" => HTMLMetaElement,
  "style" => HTMLStyleElement,
  "title" => HTMLTitleElement,
  "q" => HTMLQuoteElement,
  "blockquote" => HTMLQuoteElement,
  "ins" => HTMLModElement,
  "del" => HTMLModElement,
  "div" => HTMLDivElement,
  "span" => HTMLSpanElement,
  "p" => HTMLParagraphElement,
  "h1" => HTMLHeadingElement,
  "h2" => HTMLHeadingElement,
  "h3" => HTMLHeadingElement,
  "h4" => HTMLHeadingElement,
  "h5" => HTMLHeadingElement,
  "h6" => HTMLHeadingElement,
  "br" => HTMLBRElement,
  "hr" => HTMLHRElement,
  "pre" => HTMLPreElement,
  "body" => HTMLBodyElement,
  "head" => HTMLHeadElement,
  "html" => HTMLHtmlElement,
  "col" => HTMLTableColElement,
  "colgroup" => HTMLTableColElement,
  "datalist" => HTMLDataListElement,
  "dir" => HTMLDirectoryElement,
  "dl" => HTMLDListElement,
  "font" => HTMLFontElement,
  "frame" => HTMLFrameElement,
  "frameset" => HTMLFrameSetElement,
  "param" => HTMLParamElement
}.freeze
SVG_NAMESPACE_URI =
"http://www.w3.org/2000/svg"
HTML_NAMESPACE_URI =
"http://www.w3.org/1999/xhtml"

Class Method Summary collapse

Class Method Details

.backendObject

Convenience accessor: Dommy.backend / Dommy.backend=.



130
131
132
# File 'lib/dommy.rb', line 130

def self.backend
  Backend.current
end

.backend=(new_backend) ⇒ Object



134
135
136
# File 'lib/dommy.rb', line 134

def self.backend=(new_backend)
  Backend.current = new_backend
end

.element_class_for(tag_name, namespace_uri = nil) ⇒ Object

Map a (local name, namespace) pair to its DOM interface class. HTML-namespace names match case-SENSITIVELY (createElement lower-cases first, but createElementNS preserves case, so "SPAN" is unknown); any namespace other than HTML/SVG — including the null namespace — gets the generic Element.



4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
# File 'lib/dommy/html_elements.rb', line 4776

def self.element_class_for(tag_name, namespace_uri = nil)
  name = tag_name.to_s
  case namespace_uri
  when SVG_NAMESPACE_URI
    SVG_ELEMENT_CLASSES[name.downcase] || SVGElement
  when HTML_NAMESPACE_URI
    HTML_ELEMENT_CLASSES[name] || HTMLUnknownElement
  else
    Element
  end
end

.new_windowObject

Build a fresh, empty Window (no host). Equivalent to opening a blank document.



140
141
142
# File 'lib/dommy.rb', line 140

def self.new_window
  Window.new
end

.parse(html) ⇒ Object

Parse an HTML string and return a fresh Window.

When the input starts with <!doctype or <html>, it is parsed as a full HTML document (preserving , , etc.). Otherwise the input is treated as a body fragment and inserted into a fresh document's <body>.</p> <p>The Window has no host (standalone CRuby usage); embedders that need bridge callbacks (e.g. a wasm host) pass a host instead.</p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 118 119 120 121 122 123 124 125 126 127</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/dommy.rb', line 118</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_html'>html</span><span class='rparen'>)</span> <span class='id identifier rubyid_s'>s</span> <span class='op'>=</span> <span class='id identifier rubyid_html'>html</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='kw'>if</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\A\s*(<!doctype|<html\b)</span><span class='regexp_end'>/i</span></span><span class='rparen'>)</span> <span class='const'><span class='object_link'><a href="Dommy/Window.html" title="Dommy::Window (class)">Window</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Dommy/Window.html#initialize-instance_method" title="Dommy::Window#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>backend_doc:</span> <span class='const'><span class='object_link'><a href="Dommy/Backend.html" title="Dommy::Backend (module)">Backend</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="Dommy/Backend.html#parse-class_method" title="Dommy::Backend.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_s'>s</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>else</span> <span class='id identifier rubyid_window'>window</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Dommy/Window.html" title="Dommy::Window (class)">Window</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Dommy/Window.html#initialize-instance_method" title="Dommy::Window#initialize (method)">new</a></span></span> <span class='id identifier rubyid_window'>window</span><span class='period'>.</span><span class='id identifier rubyid_document'>document</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span><span class='period'>.</span><span class='id identifier rubyid_inner_html'>inner_html</span> <span class='op'>=</span> <span class='id identifier rubyid_s'>s</span> <span class='id identifier rubyid_window'>window</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="structured_clone-class_method"> .<strong>structured_clone</strong>(value, memo = {}) ⇒ <tt>Object</tt> </h3><div class="docstring"> <div class="discussion"> <p><code>structuredClone(value)</code> — deep clone for plain Ruby values and DOM nodes (via <code>cloneNode(true)</code>). Mirrors the JS structured-clone algorithm for the subset we support:</p> <pre class="code ruby"><code class="ruby">- primitives (String / Numeric / Boolean / nil) → copied - Array / Hash / Set → deep-cloned - DOM nodes (anything responding to `clone_node`) → deep-cloned - cyclic structures → preserved - Proc / Method / Class / Module / IO → DataCloneError </code></pre> <p>Symbols are passed through unchanged (Ruby has no <code>Symbol</code> clone concept; JS treats Symbols as DataCloneError, but Ruby code uses them as hash keys so this is the pragmatic choice).</p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/dommy.rb', line 157</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_memo'>memo</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>return</span> <span class='id identifier rubyid_memo'>memo</span><span class='lbracket'>[</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_memo'>memo</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='rparen'>)</span> <span class='kw'>case</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>when</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='const'>Numeric</span><span class='comma'>,</span> <span class='const'>Symbol</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>when</span> <span class='const'>String</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span> <span class='kw'>when</span> <span class='const'>Array</span> <span class='id identifier rubyid_arr'>arr</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> <span class='id identifier rubyid_memo'>memo</span><span class='lbracket'>[</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_arr'>arr</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_arr'>arr</span> <span class='op'><<</span> <span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='comma'>,</span> <span class='id identifier rubyid_memo'>memo</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='id identifier rubyid_arr'>arr</span> <span class='kw'>when</span> <span class='const'>Hash</span> <span class='id identifier rubyid_h'>h</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> <span class='id identifier rubyid_memo'>memo</span><span class='lbracket'>[</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_h'>h</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_h'>h</span><span class='lbracket'>[</span><span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_memo'>memo</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='comma'>,</span> <span class='id identifier rubyid_memo'>memo</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='id identifier rubyid_h'>h</span> <span class='kw'>when</span> <span class='const'>Set</span> <span class='id identifier rubyid_s'>s</span> <span class='op'>=</span> <span class='const'>Set</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_memo'>memo</span><span class='lbracket'>[</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_object_id'>object_id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_s'>s</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_s'>s</span> <span class='op'><<</span> <span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='comma'>,</span> <span class='id identifier rubyid_memo'>memo</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='id identifier rubyid_s'>s</span> <span class='kw'>when</span> <span class='const'>Time</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span> <span class='kw'>when</span> <span class='const'>Regexp</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span> <span class='kw'>when</span> <span class='const'>Proc</span><span class='comma'>,</span> <span class='const'>Method</span><span class='comma'>,</span> <span class='const'>UnboundMethod</span><span class='comma'>,</span> <span class='const'>IO</span><span class='comma'>,</span> <span class='const'>Class</span><span class='comma'>,</span> <span class='const'>Module</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="Dommy/DOMException.html" title="Dommy::DOMException (class)">DOMException</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Dommy/DOMException/DataCloneError.html" title="Dommy::DOMException::DataCloneError (class)">DataCloneError</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> cannot be cloned</span><span class='tstring_end'>"</span></span> <span class='kw'>else</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:clone_node</span><span class='rparen'>)</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_clone_node'>clone_node</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span> <span class='kw'>else</span> <span class='comment'># Fallback: rely on the object's own `dup` (which handles </span> <span class='comment'># custom classes the user might pass through). </span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> <div class="method_details "> <h3 class="signature " id="structuredClone-class_method"> .<strong>structuredClone</strong>(value) ⇒ <tt>Object</tt> </h3><div class="docstring"> <div class="discussion"> <p>JS-style global alias for symmetry with <code>window.structuredClone(...)</code>.</p> </div> </div> <div class="tags"> </div><table class="source_code"> <tr> <td> <pre class="lines"> 199 200 201</pre> </td> <td> <pre class="code"><span class="info file"># File 'lib/dommy.rb', line 199</span> <span class='kw'>def</span> <span class='const'><span class='object_link'><a href="" title="Dommy (module)">Dommy</a></span></span><span class='period'>.</span><span class='id identifier rubyid_structuredClone'>structuredClone</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='id identifier rubyid_structured_clone'>structured_clone</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='kw'>end</span></pre> </td> </tr> </table> </div> </div> </div> <div id="footer"> Generated on Mon Jul 13 13:56:40 2026 by <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.44 (ruby-4.0.2). </div> </div> </body> </html>