Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/docker/metadata-ac…
Browse files Browse the repository at this point in the history
…tion-5
  • Loading branch information
kateinoigakukun authored Oct 29, 2023
2 parents 76837f3 + c4c5083 commit 1b97b69
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 120 deletions.
9 changes: 9 additions & 0 deletions ext/js/lib/js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ def new(*args)
JS.global[:Reflect].construct(self, args.to_js)
end

# Converts +self+ to an Array:
#
# JS.eval("return [1, 2, 3]").to_a.map(&:to_i) # => [1, 2, 3]
# JS.global[:document].querySelectorAll("p").to_a # => [[object HTMLParagraphElement], ...
def to_a
as_array = JS.global[:Array].from(self)
Array.new(as_array[:length].to_i) { as_array[_1] }
end

# Provide a shorthand form for JS::Object#call
#
# This method basically calls the JavaScript method with the same
Expand Down
Loading

0 comments on commit 1b97b69

Please sign in to comment.