Class: Native::Object
- Inherits:
-
BasicObject
- Includes:
- Native
- Defined in:
- opal/stdlib/native.rb
Instance Method Summary
collapse
Methods included from Native
call, convert, included, #initialize, is_a?, #to_n, try_convert
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args, &block) ⇒ Object
226
227
228
229
230
231
232
233
234
235
|
# File 'opal/stdlib/native.rb', line 226
def method_missing(mid, *args, &block)
%x{
if (mid.charAt(mid.length - 1) === '=') {
return #{self[mid.slice(0, mid.length - 1)] = args[0]};
}
else {
return #{::Native.call(@native, mid, *args, &block)};
}
}
end
|
Instance Method Details
#==(other) ⇒ Object
157
158
159
|
# File 'opal/stdlib/native.rb', line 157
def ==(other)
`#@native === #{Native.try_convert(other)}`
end
|
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'opal/stdlib/native.rb', line 183
def [](key)
%x{
var prop = #@native[key];
if (prop instanceof Function) {
return prop;
}
else {
return #{::Native.call(@native, key)}
}
}
end
|
#[]=(key, value) ⇒ Object
196
197
198
199
200
201
202
203
204
|
# File 'opal/stdlib/native.rb', line 196
def []=(key, value)
native = Native.try_convert(value)
if `#{native} === nil`
`#@native[key] = #{value}`
else
`#@native[key] = #{native}`
end
end
|
251
252
253
|
# File 'opal/stdlib/native.rb', line 251
def class
`self.$$class`
end
|
#each(*args) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'opal/stdlib/native.rb', line 169
def each(*args)
if block_given?
%x{
for (var key in #@native) {
#{yield `key`, `#@native[key]`}
}
}
self
else
method_missing(:each, *args)
end
end
|
#has_key?(name) ⇒ Boolean
Also known as:
key?, include?, member?
161
162
163
|
# File 'opal/stdlib/native.rb', line 161
def has_key?(name)
`Opal.hasOwnProperty.call(#@native, #{name})`
end
|
259
260
261
|
# File 'opal/stdlib/native.rb', line 259
def inspect
"#<Native:#{`String(#@native)`}>"
end
|
#instance_of?(klass) ⇒ Boolean
247
248
249
|
# File 'opal/stdlib/native.rb', line 247
def instance_of?(klass)
`self.$$class === klass`
end
|
#is_a?(klass) ⇒ Boolean
Also known as:
kind_of?
241
242
243
|
# File 'opal/stdlib/native.rb', line 241
def is_a?(klass)
`Opal.is_a(self, klass)`
end
|
#merge!(other) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
|
# File 'opal/stdlib/native.rb', line 206
def merge!(other)
%x{
var other = #{Native.convert(other)};
for (var prop in other) {
#@native[prop] = other[prop];
}
}
self
end
|
237
238
239
|
# File 'opal/stdlib/native.rb', line 237
def nil?
false
end
|
#respond_to?(name, include_all = false) ⇒ Boolean
218
219
220
|
# File 'opal/stdlib/native.rb', line 218
def respond_to?(name, include_all = false)
Kernel.instance_method(:respond_to?).bind(self).call(name, include_all)
end
|
#respond_to_missing?(name) ⇒ Boolean
222
223
224
|
# File 'opal/stdlib/native.rb', line 222
def respond_to_missing?(name)
`Opal.hasOwnProperty.call(#@native, #{name})`
end
|
#to_a(options = {}, &block) ⇒ Object
255
256
257
|
# File 'opal/stdlib/native.rb', line 255
def to_a(options = {}, &block)
Native::Array.new(@native, options, &block).to_a
end
|