Skip to content

Commit 67ae96b

Browse files
Add doc comment for JS::Object#method_missing
1 parent e314d5d commit 67ae96b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ext/js/lib/js.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ def new(*args)
137137
JS.global[:Reflect].construct(self, args.to_js)
138138
end
139139

140+
# Provide a shorthand form for JS::Object#call
141+
#
142+
# This method basically calls the JavaScript method with the same
143+
# name as the Ruby method name as is using JS::Object#call.
144+
#
145+
# Exceptions are the following cases:
146+
# * If the method name ends with a question mark (?), the question mark is removed
147+
# and the method is called as a predicate method. The return value is converted to
148+
# a Ruby boolean value automatically.
149+
#
150+
# This shorthand is unavailable for the following cases and you need to use
151+
# JS::Object#call instead:
152+
# * If the method name is invalid as a Ruby method name (e.g. contains a hyphen, reserved word, etc.)
153+
# * If the method name is already defined as a Ruby method under JS::Object
154+
# * If the JavaScript method name ends with a question mark (?)
140155
def method_missing(sym, *args, &block)
141156
sym_str = sym.to_s
142157
if sym_str.end_with?("?")
@@ -150,6 +165,9 @@ def method_missing(sym, *args, &block)
150165
end
151166
end
152167

168+
# Check if a JavaScript method exists
169+
#
170+
# See JS::Object#method_missing for details.
153171
def respond_to_missing?(sym, include_private)
154172
return true if super
155173
sym_str = sym.to_s

0 commit comments

Comments
 (0)