Class: JavaScript::Object
Instance Method Summary
collapse
Constructor Details
#initialize(proto = nil) ⇒ Object
Returns a new instance of Object.
57
58
59
|
# File 'lib/javascript.rb', line 57
def initialize(proto = nil)
@hash = { __proto__: proto }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/javascript.rb', line 100
def method_missing(name, *args, &block)
if name =~ /=\z/
self[name[0...-1].to_sym] = args[0]
elsif Function === self[name]
self[name].apply(self, args)
else
self[name]
end
end
|
Instance Method Details
#!=(other) ⇒ Object
83
84
85
|
# File 'lib/javascript.rb', line 83
def !=(other)
!(self == other)
end
|
#==(other) ⇒ Object
75
76
77
|
# File 'lib/javascript.rb', line 75
def ==(other)
__method__(:==).call(other)
end
|
#===(other) ⇒ Object
79
80
81
|
# File 'lib/javascript.rb', line 79
def ===(other)
self == other
end
|
61
62
63
64
65
66
67
68
69
|
# File 'lib/javascript.rb', line 61
def [](key)
if @hash.key?(key)
@hash[key]
elsif __proto__
__proto__[key]
else
nil
end
end
|
#[]=(key, value) ⇒ Object
71
72
73
|
# File 'lib/javascript.rb', line 71
def []=(key, value)
@hash[key.to_sym] = value
end
|
#__defined__?(key) ⇒ Boolean
95
96
97
|
# File 'lib/javascript.rb', line 95
def __defined__?(key)
@hash.key?(key) || (__proto__ && __proto__.__defined__?(key))
end
|
87
88
89
|
# File 'lib/javascript.rb', line 87
def __hash__
@hash
end
|
#__proto__ ⇒ Object
91
92
93
|
# File 'lib/javascript.rb', line 91
def __proto__
@hash[:__proto__]
end
|