Class: String

Inherits:
Object show all
Defined in:
opal/stdlib/json.rb,
opal/stdlib/native.rb,
opal/stdlib/encoding.rb

Instance Method Summary collapse

Instance Method Details

#bytesObject


134
135
136
# File 'opal/stdlib/encoding.rb', line 134

def bytes
  each_byte.to_a
end

#bytesizeObject


138
139
140
# File 'opal/stdlib/encoding.rb', line 138

def bytesize
  @encoding.bytesize(self)
end

#each_byte(&block) ⇒ Object


142
143
144
145
146
147
148
# File 'opal/stdlib/encoding.rb', line 142

def each_byte(&block)
  return enum_for :each_byte unless block_given?

  @encoding.each_byte(self, &block)

  self
end

#encodingObject


150
151
152
# File 'opal/stdlib/encoding.rb', line 150

def encoding
  @encoding
end

#force_encoding(encoding) ⇒ Object


154
155
156
157
158
159
160
161
162
163
164
165
# File 'opal/stdlib/encoding.rb', line 154

def force_encoding(encoding)
  encoding = Encoding.find(encoding)

  return self if encoding == @encoding

  %x{
    var result = new String(self);
    result.encoding = encoding;

    return result;
  }
end

#getbyte(idx) ⇒ Object


167
168
169
# File 'opal/stdlib/encoding.rb', line 167

def getbyte(idx)
  @encoding.getbyte(self, idx)
end

#to_nObject


364
365
366
# File 'opal/stdlib/native.rb', line 364

def to_n
  `self.valueOf()`
end