Class: Array::Wrapper
- Inherits:
-
Object
show all
- Defined in:
- opal/opal/corelib/array/inheritance.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &block) ⇒ Wrapper
Returns a new instance of Wrapper
37
38
39
|
# File 'opal/opal/corelib/array/inheritance.rb', line 37
def initialize(*args, &block)
@literal = Array.new(*args, &block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'opal/opal/corelib/array/inheritance.rb', line 41
def method_missing(*args, &block)
result = @literal.__send__(*args, &block)
if `result === #@literal`
self
else
result
end
end
|
Class Method Details
.[](*objects) ⇒ Object
33
34
35
|
# File 'opal/opal/corelib/array/inheritance.rb', line 33
def self.[](*objects)
allocate(objects)
end
|
.allocate(array = []) ⇒ Object
21
22
23
24
25
|
# File 'opal/opal/corelib/array/inheritance.rb', line 21
def self.allocate(array = [])
obj = super()
`obj.literal = array`
obj
end
|
.new(*args, &block) ⇒ Object
27
28
29
30
31
|
# File 'opal/opal/corelib/array/inheritance.rb', line 27
def self.new(*args, &block)
obj = allocate
obj.initialize(*args, &block)
obj
end
|
Instance Method Details
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'opal/opal/corelib/array/inheritance.rb', line 84
def *(other)
%x{
var result = #{@literal * other};
if (result.$$is_array) {
return #{self.class.allocate(`result`)}
}
else {
return result;
}
}
end
|
124
125
126
|
# File 'opal/opal/corelib/array/inheritance.rb', line 124
def +(other)
@literal + other
end
|
120
121
122
|
# File 'opal/opal/corelib/array/inheritance.rb', line 120
def -(other)
@literal - other
end
|
#==(other) ⇒ Object
59
60
61
|
# File 'opal/opal/corelib/array/inheritance.rb', line 59
def ==(other)
@literal == other
end
|
#[](index, length = undefined) ⇒ Object
Also known as:
slice
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'opal/opal/corelib/array/inheritance.rb', line 97
def [](index, length = undefined)
%x{
var result = #{@literal.slice(index, length)};
if (result.$$is_array && (index.$$is_range || length !== undefined)) {
return #{self.class.allocate(`result`)}
}
else {
return result;
}
}
end
|
#eql?(other) ⇒ Boolean
63
64
65
|
# File 'opal/opal/corelib/array/inheritance.rb', line 63
def eql?(other)
@literal.eql?(other)
end
|
#flatten(level = undefined) ⇒ Object
116
117
118
|
# File 'opal/opal/corelib/array/inheritance.rb', line 116
def flatten(level = undefined)
self.class.allocate(@literal.flatten(level))
end
|
79
80
81
|
# File 'opal/opal/corelib/array/inheritance.rb', line 79
def hash
@literal.hash
end
|
#initialize_copy(other) ⇒ Object
51
52
53
|
# File 'opal/opal/corelib/array/inheritance.rb', line 51
def initialize_copy(other)
@literal = `other.literal`.clone
end
|
75
76
77
|
# File 'opal/opal/corelib/array/inheritance.rb', line 75
def inspect
@literal.inspect
end
|
#respond_to?(name) ⇒ Boolean
55
56
57
|
# File 'opal/opal/corelib/array/inheritance.rb', line 55
def respond_to?(name, *)
super || @literal.respond_to?(name)
end
|
67
68
69
|
# File 'opal/opal/corelib/array/inheritance.rb', line 67
def to_a
@literal
end
|
71
72
73
|
# File 'opal/opal/corelib/array/inheritance.rb', line 71
def to_ary
self
end
|
112
113
114
|
# File 'opal/opal/corelib/array/inheritance.rb', line 112
def uniq
self.class.allocate(@literal.uniq)
end
|