Class: String::Wrapper
- Inherits:
-
Object
show all
- Defined in:
- opal/opal/corelib/string/inheritance.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(string = '') ⇒ Wrapper
Returns a new instance of Wrapper
36
37
38
|
# File 'opal/opal/corelib/string/inheritance.rb', line 36
def initialize(string = '')
@literal = string
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'opal/opal/corelib/string/inheritance.rb', line 40
def method_missing(*args, &block)
result = @literal.__send__(*args, &block)
if `result.$$is_string != null`
if `result == #@literal`
self
else
self.class.allocate(result)
end
else
result
end
end
|
Class Method Details
.[](*objects) ⇒ Object
32
33
34
|
# File 'opal/opal/corelib/string/inheritance.rb', line 32
def self.[](*objects)
allocate(objects)
end
|
.allocate(string = "") ⇒ Object
20
21
22
23
24
|
# File 'opal/opal/corelib/string/inheritance.rb', line 20
def self.allocate(string = "")
obj = super()
`obj.literal = string`
obj
end
|
.new(*args, &block) ⇒ Object
26
27
28
29
30
|
# File 'opal/opal/corelib/string/inheritance.rb', line 26
def self.new(*args, &block)
obj = allocate
obj.initialize(*args, &block)
obj
end
|
Instance Method Details
#%(data) ⇒ Object
114
115
116
|
# File 'opal/opal/corelib/string/inheritance.rb', line 114
def %(data)
@literal % data
end
|
#*(other) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'opal/opal/corelib/string/inheritance.rb', line 83
def *(other)
%x{
var result = #{@literal * other};
if (result.$$is_string) {
return #{self.class.allocate(`result`)}
}
else {
return result;
}
}
end
|
#+(other) ⇒ Object
79
80
81
|
# File 'opal/opal/corelib/string/inheritance.rb', line 79
def +(other)
@literal + other
end
|
#==(other) ⇒ Object
Also known as:
eql?, ===
62
63
64
|
# File 'opal/opal/corelib/string/inheritance.rb', line 62
def ==(other)
@literal == other
end
|
#each_line(separator = $/) ⇒ Object
104
105
106
107
|
# File 'opal/opal/corelib/string/inheritance.rb', line 104
def each_line(separator = $/)
return enum_for :each_line, separator unless block_given?
@literal.each_line(separator){|str| yield self.class.allocate(str)}
end
|
#initialize_copy(other) ⇒ Object
54
55
56
|
# File 'opal/opal/corelib/string/inheritance.rb', line 54
def initialize_copy(other)
@literal = `other.literal`.clone
end
|
#inspect ⇒ Object
75
76
77
|
# File 'opal/opal/corelib/string/inheritance.rb', line 75
def inspect
@literal.inspect
end
|
#lines(separator = $/, &block) ⇒ Object
109
110
111
112
|
# File 'opal/opal/corelib/string/inheritance.rb', line 109
def lines(separator = $/, &block)
e = each_line(separator, &block)
block ? self : e.to_a
end
|
#replace(string) ⇒ Object
100
101
102
|
# File 'opal/opal/corelib/string/inheritance.rb', line 100
def replace(string)
@literal = string
end
|
#respond_to?(name) ⇒ Boolean
58
59
60
|
# File 'opal/opal/corelib/string/inheritance.rb', line 58
def respond_to?(name, *)
super || @literal.respond_to?(name)
end
|
#split(pattern = undefined, limit = undefined) ⇒ Object
96
97
98
|
# File 'opal/opal/corelib/string/inheritance.rb', line 96
def split(pattern = undefined, limit = undefined)
@literal.split(pattern, limit).map{|str| self.class.allocate(str)}
end
|
#to_s ⇒ Object
Also known as:
to_str
69
70
71
|
# File 'opal/opal/corelib/string/inheritance.rb', line 69
def to_s
@literal
end
|