Class: Twostroke::Runtime::Types::StringObject
- Inherits:
-
Object
- Object
- Value
- Object
- Twostroke::Runtime::Types::StringObject
show all
- Defined in:
- lib/twostroke/runtime/types/string_object.rb
Instance Attribute Summary collapse
Attributes inherited from Object
#_class, #data, #extensible, #prototype
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Object
#can_put, #construct, #constructing?, #default_value, #define_own_property, #delete, #delete!, #generic_items, #get_own_property, #get_property, #has_accessor, #proto_put, #put, set_global_prototype, #typeof
Methods inherited from Value
#has_instance, #typeof
Constructor Details
Returns a new instance of StringObject.
10
11
12
13
14
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 10
def initialize(string)
@prototype = StringObject.constructor_function.get("prototype")
@string = string
super()
end
|
Instance Attribute Details
Returns the value of attribute string.
9
10
11
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 9
def string
@string
end
|
Class Method Details
.constructor_function ⇒ Object
Instance Method Details
#each_enumerable_property(&bk) ⇒ Object
46
47
48
49
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 46
def each_enumerable_property(&bk)
(0...string.length).map(&:to_s).each &bk
super &bk
end
|
#get(prop, this = self) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 20
def get(prop, this = self)
if prop =~ /\A\d+\z/
String.new string[prop.to_i]
else
super prop, this
end
end
|
#has_own_property(prop) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 37
def has_own_property(prop)
if prop =~ /\A\d+\z/
i = prop.to_i
i >= 0 && i < string.size
else
super prop
end
end
|
#has_property(prop) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 28
def has_property(prop)
if prop =~ /\A\d+\z/
i = prop.to_i
i >= 0 && i < string.size
else
super prop
end
end
|
#primitive_value ⇒ Object
16
17
18
|
# File 'lib/twostroke/runtime/types/string_object.rb', line 16
def primitive_value
String.new string
end
|