Class: String
- Defined in:
- lib/source/ruby.rb,
lib/source/redshift/request.rb
Overview
A String
object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String
objects may be created using String::new
or as literals. Typically, methods with names ending in “!
” modify their receiver, while those without a “!
” return a new String
.
Direct Known Subclasses
Red::AssignmentNode, Red::CallNode, Red::ControlNode, Red::DataNode, Red::DefinitionNode, Red::LiteralNode, Red::VariableNode
Instance Method Summary collapse
-
#%(arg) ⇒ Object
call-seq: str % arg -> string.
-
#*(n) ⇒ Object
call-seq: str * num -> string.
-
#+(str) ⇒ Object
call-seq: str + other -> string.
-
#<<(obj) ⇒ Object
call-seq: str << num -> str str << obj -> str str.concat(num) -> str str.concat(obj) -> str.
-
#<=>(str) ⇒ Object
call-seq: str <=> other -> -1, 0, 1.
-
#==(str) ⇒ Object
call-seq: str == other -> true or false.
-
#=~(str) ⇒ Object
FIX: Incomplete.
-
#[] ⇒ Object
call-seq: str -> integer or nil str[num, num] -> string or nil str -> string or nil str -> string or nil str[regexp, num] -> string or nil str -> string or nil str.slice(num) -> integer or nil str.slice(num, num) -> string or nil str.slice(range) -> string or nil str.slice(regexp) -> string or nil str.slice(regexp, num) -> string or nil str.slice(other) -> string or nil.
- #[]= ⇒ Object
-
#capitalize ⇒ Object
call-seq: str.capitalize -> string.
-
#capitalize! ⇒ Object
call-seq: str.capitalize! -> str or nil.
-
#casecmp(str) ⇒ Object
call-seq: str.casecmp(other) -> -1, 0, 1.
-
#center ⇒ Object
FIX: Incomplete.
-
#chomp ⇒ Object
FIX: Incomplete.
-
#chomp! ⇒ Object
FIX: Incomplete.
-
#chop ⇒ Object
FIX: Incomplete.
-
#chop! ⇒ Object
FIX: Incomplete.
-
#concat(obj) ⇒ Object
call-seq: str << num -> str str << obj -> str str.concat(num) -> str str.concat(obj) -> str.
-
#count ⇒ Object
FIX: Incomplete.
-
#crypt ⇒ Object
FIX: Incomplete.
-
#delete ⇒ Object
FIX: Incomplete.
-
#delete! ⇒ Object
FIX: Incomplete.
-
#downcase ⇒ Object
call-seq: str.downcase -> string.
-
#downcase! ⇒ Object
call-seq: str.downcase! -> str or nil.
-
#each ⇒ Object
FIX: Incomplete.
-
#each_byte ⇒ Object
FIX: Incomplete.
-
#each_line ⇒ Object
FIX: Incomplete.
-
#empty? ⇒ Boolean
call-seq: str.empty? -> true or false.
-
#eql?(str) ⇒ Boolean
call-seq: str.eql?(other) -> true or false.
-
#gsub ⇒ Object
FIX: Incomplete.
-
#gsub! ⇒ Object
FIX: Incomplete.
-
#hash ⇒ Object
:nodoc:.
-
#hex ⇒ Object
call-seq: str.hex -> num.
-
#include?(obj) ⇒ Boolean
call-seq: str.include?(other) -> true or false str.include?(num) -> true or false.
-
#index ⇒ Object
FIX: Incomplete.
-
#initialize(string = `''`) ⇒ String
constructor
call-seq: String.new(str = ”) -> string.
-
#insert ⇒ Object
FIX: Incomplete.
-
#inspect ⇒ Object
FIX: Incomplete.
-
#intern ⇒ Object
call-seq: str.intern -> symbol str.to_sym -> symbol.
-
#length ⇒ Object
call-seq: str.length -> integer str.size -> integer.
-
#ljust ⇒ Object
FIX: Incomplete.
-
#lstrip ⇒ Object
call-seq: str.lstrip -> string.
-
#lstrip! ⇒ Object
call-seq: str.lstrip! -> str.
-
#match(pattern) ⇒ Object
call-seq: str.match(pattern) -> matchdata or nil.
-
#next ⇒ Object
call-seq: str.next -> string str.succ -> string.
-
#next! ⇒ Object
call-seq: str.next! -> str str.succ! -> str.
-
#oct ⇒ Object
call-seq: str.oct -> num.
-
#replace(str) ⇒ Object
call-seq: str.replace(other) -> str.
-
#reverse ⇒ Object
call-seq: str.reverse -> string.
-
#reverse! ⇒ Object
call-seq: str.reverse! -> str.
-
#rindex ⇒ Object
FIX: Incomplete.
-
#rjust ⇒ Object
FIX: Incomplete.
-
#rstrip ⇒ Object
call-seq: str.rstrip -> string.
-
#rstrip! ⇒ Object
call-seq: str.rstrip! -> str.
-
#scan ⇒ Object
FIX: Incomplete.
-
#size ⇒ Object
call-seq: str.length -> integer str.size -> integer.
-
#slice ⇒ Object
call-seq: str -> integer or nil str[num, num] -> string or nil str -> string or nil str -> string or nil str[regexp, num] -> string or nil str -> string or nil str.slice(num) -> integer or nil str.slice(num, num) -> string or nil str.slice(range) -> string or nil str.slice(regexp) -> string or nil str.slice(regexp, num) -> string or nil str.slice(other) -> string or nil.
-
#slice! ⇒ Object
call-seq: str.slice!(num) -> num or nil str.slice!(num, num) -> string or nil str.slice!(range) -> string or nil str.slice!(regexp) -> string or nil str.slice!(other) -> string or nil.
-
#split(pattern = /\s+/, limit = nil) ⇒ Object
FIX: Incomplete.
-
#squeeze ⇒ Object
FIX: Incomplete.
-
#strip ⇒ Object
call-seq: str.strip -> string.
-
#strip! ⇒ Object
call-seq: str.strip! -> str.
-
#strip_scripts(evaluate = false) ⇒ Object
call-seq: str.strip_scripts(evaluate = false) -> string.
-
#sub ⇒ Object
FIX: Incomplete.
-
#sub! ⇒ Object
FIX: Incomplete.
-
#succ ⇒ Object
call-seq: str.next -> string str.succ -> string.
-
#succ! ⇒ Object
call-seq: str.next! -> str str.succ! -> str.
-
#sum ⇒ Object
FIX: Incomplete.
-
#swapcase ⇒ Object
call-seq: str.swapcase -> string.
-
#swapcase! ⇒ Object
call-seq: str.swapcase! -> str or nil.
-
#to_f ⇒ Object
call-seq: str.to_f -> float.
-
#to_i(base = 10) ⇒ Object
call-seq: str.to_i -> integer.
-
#to_s ⇒ Object
call-seq: str.to_s -> str str.to_str -> str.
-
#to_str ⇒ Object
call-seq: str.to_s -> str str.to_str -> str.
-
#to_sym ⇒ Object
call-seq: str.intern -> symbol str.to_sym -> symbol.
-
#tr ⇒ Object
FIX: Incomplete.
-
#tr! ⇒ Object
FIX: Incomplete.
-
#tr_s ⇒ Object
FIX: Incomplete.
-
#tr_s! ⇒ Object
FIX: Incomplete.
-
#upcase ⇒ Object
call-seq: str.upcase -> string.
-
#upcase! ⇒ Object
call-seq: str.upcase! -> str or nil.
-
#upto(str, &block) ⇒ Object
FIX: Incomplete.
Constructor Details
#initialize(string = `''`) ⇒ String
call-seq:
String.new(str = '') -> string
Returns a new string object containing a copy of str.
5304 5305 5306 |
# File 'lib/source/ruby.rb', line 5304 def initialize(string = `''`) `this.__value__=string.__value__||string` end |
Instance Method Details
#%(arg) ⇒ Object
call-seq:
str % arg -> string
Format – uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array
containing the values to be substituted. See Kernel::sprintf
for details of the format string.
"%05d" % 123 #=> "00123"
"%s: %08x" % ['ID', self.__id__] #=> "ID: 200e14d6"
5320 5321 5322 5323 |
# File 'lib/source/ruby.rb', line 5320 def %(arg) `arg.m$class()==c$Array?arg.unshift(this):arg=[this,arg]` `m$sprintf.apply(null,arg)` end |
#*(n) ⇒ Object
call-seq:
str * num -> string
Copy – returns a new string containing num copies of str.
'abc ' * 3 #=> "abc abc abc "
5332 5333 5334 5335 |
# File 'lib/source/ruby.rb', line 5332 def *(n) `for(var i=0,str=this.__value__,result='';i<n;++i){result+=str;}` return `$q(result)` end |
#+(str) ⇒ Object
call-seq:
str + other -> string
Concatenation – returns a new string containing other concatenated to str.
'abc' + 'def' #=> 'abcdef'
5345 5346 5347 |
# File 'lib/source/ruby.rb', line 5345 def +(str) `$q(this.__value__ + str.__value__)` end |
#<<(obj) ⇒ Object
call-seq:
str << num -> str
str << obj -> str
str.concat(num) -> str
str.concat(obj) -> str
Append – concatenates the given object to str. If the object is an integer between 0 and 255, it is converted to a character before concatenation.
s = 'abc'
s << 'def' #=> "abcdef"
s << 103 << 104 #=> "abcdefgh"
5364 5365 5366 5367 |
# File 'lib/source/ruby.rb', line 5364 def <<(obj) `this.__value__+=(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__)` return self end |
#<=>(str) ⇒ Object
call-seq:
str <=> other -> -1, 0, 1
Comparison – returns -1 if other is less than, 0 if other is equal to, and 1 if other is greater than str. If the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered greater than the shorter one.
<=>
is the basis for the methods <
, <=
, >
, >=
, and between?
, included from module Comparable
. The method String#==
does not use Comparable#==
.
'abcdef' <=> 'abcde' #=> 1
'abcdef' <=> 'abcdef' #=> 0
'abcdef' <=> 'abcdefg' #=> -1
'abcdef' <=> 'ABCDEF' #=> 1
5388 5389 5390 5391 5392 5393 5394 5395 |
# File 'lib/source/ruby.rb', line 5388 def <=>(str) `if(str.m$class()!=c$String){return nil;}` `var tv=this.__value__,sv=str.__value__` `if(tv>sv){return 1;}` `if(tv==sv){return 0;}` `if(tv<sv){return -1;}` return nil end |
#==(str) ⇒ Object
call-seq:
str == other -> true or false
Equality – if other is not a String
, returns false. Otherwise, returns true
if str <=> obj
returns zero.
5403 5404 5405 5406 |
# File 'lib/source/ruby.rb', line 5403 def ==(str) `if(str.m$class()!=c$String){return false;}` return `this.m$_ltgt(str)==0` end |
#[] ⇒ Object
call-seq:
str[num] -> integer or nil
str[num, num] -> string or nil
str[range] -> string or nil
str[regexp] -> string or nil
str[regexp, num] -> string or nil
str[other] -> string or nil
str.slice(num) -> integer or nil
str.slice(num, num) -> string or nil
str.slice(range) -> string or nil
str.slice(regexp) -> string or nil
str.slice(regexp, num) -> string or nil
str.slice(other) -> string or nil
FIX: Incomplete
5427 5428 |
# File 'lib/source/ruby.rb', line 5427 def [] end |
#[]= ⇒ Object
call-seq:
str[num] = num -> num
str[num] = string -> string
str[num, num] = string -> string
str[range] = string -> string
str[regexp] = string -> string
str[regexp, num] = string -> string
str[other] = string -> string
FIX: Incomplete
5440 5441 |
# File 'lib/source/ruby.rb', line 5440 def []= end |
#capitalize ⇒ Object
call-seq:
str.capitalize -> string
Returns a copy of str with the first character converted to uppercase and the remainder to lowercase.
'abcdef'.capitalize #=> "Abcdef"
'ABCDEF'.capitalize #=> "Abcdef"
'123ABC'.capitalize #=> "123abc"
5453 5454 5455 5456 |
# File 'lib/source/ruby.rb', line 5453 def capitalize `var v=this.__value__` `$q(v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase())` end |
#capitalize! ⇒ Object
call-seq:
str.capitalize! -> str or nil
Returns str with the first character converted to uppercase and the remainder to lowercase, or nil
if no changes were made.
s = 'abcdef'
s.capitalize! #=> "Abcdef"
s.capitalize! #=> nil
s #=> "Abcdef"
5470 5471 5472 5473 5474 |
# File 'lib/source/ruby.rb', line 5470 def capitalize! `var v=this.__value__` `this.__value__=v.slice(0,1).toUpperCase()+v.slice(1,v.length).toLowerCase()` return `v==this.__value__?nil:this` end |
#casecmp(str) ⇒ Object
call-seq:
str.casecmp(other) -> -1, 0, 1
Case-insensitive version of String#<=>
.
'abcdef'.casecmp('abcde') #=> 1
'aBcDeF'.casecmp('abcdef') #=> 0
'abcdef'.casecmp('abcdefg') #=> -1
'abcdef'.casecmp('ABCDEF') #=> 0
5486 5487 5488 5489 5490 5491 5492 5493 |
# File 'lib/source/ruby.rb', line 5486 def casecmp(str) `if(str.m$class()!=c$String){return nil;}` `var tv=this.__value__.toLowerCase(),sv=str.__value__.toLowerCase()` `if(tv>sv){return 1;}` `if(tv==sv){return 0;}` `if(tv<sv){return -1;}` return nil end |
#concat(obj) ⇒ Object
call-seq:
str << num -> str
str << obj -> str
str.concat(num) -> str
str.concat(obj) -> str
Append – concatenates the given object to str. If the object is an integer between 0 and 255, it is converted to a character before concatenation.
a = 'abc'
a.concat('def') #=> "abcdef"
a.concat(103).concat(104) #=> "abcdefgh"
5530 5531 5532 5533 |
# File 'lib/source/ruby.rb', line 5530 def concat(obj) `this.__value__+=(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__)` return self end |
#downcase ⇒ Object
call-seq:
str.downcase -> string
Returns a copy of str with all uppercase letters replaced with their lowercase counterparts.
'aBCDEf'.downcase #=> "abcdef"
5559 5560 5561 |
# File 'lib/source/ruby.rb', line 5559 def downcase `$q(this.__value__.toLowerCase())` end |
#downcase! ⇒ Object
call-seq:
str.downcase! -> str or nil
Returns str with all uppercase letters replaced with their lowercase counterparts, or nil
if no changes were made.
s = 'aBCDEf'
s.downcase! #=> "abcdef"
s.downcase! #=> nil
s #=> "abcdef"
5575 5576 5577 5578 5579 |
# File 'lib/source/ruby.rb', line 5575 def downcase! `var v=this.__value__` `this.__value__=v.toLowerCase()` return `v==this.__value__?nil:this` end |
#each_byte ⇒ Object
FIX: Incomplete
5586 5587 |
# File 'lib/source/ruby.rb', line 5586 def each_byte end |
#each_line ⇒ Object
FIX: Incomplete
5590 5591 |
# File 'lib/source/ruby.rb', line 5590 def each_line end |
#empty? ⇒ Boolean
call-seq:
str.empty? -> true or false
Returns true
if str has a length of zero.
'abcdef'.empty? #=> false
''.empty? #=> true
5601 5602 5603 |
# File 'lib/source/ruby.rb', line 5601 def empty? `this.__value__==''` end |
#eql?(str) ⇒ Boolean
call-seq:
str.eql?(other) -> true or false
Two strings are equal if they have the same length and content.
5610 5611 5612 5613 |
# File 'lib/source/ruby.rb', line 5610 def eql?(str) `if(str.m$class()!=c$String){return false;}` `this.__value__==str.__value__` end |
#hash ⇒ Object
:nodoc:
5623 5624 5625 |
# File 'lib/source/ruby.rb', line 5623 def hash # :nodoc: `'q_'+this.__value__` end |
#hex ⇒ Object
call-seq:
str.hex -> num
Treats leading characters from str as a string of hexadecimal digits (with an optional sign and an optional 0x) and returns the corresponding number. Zero is returned on error.
'0x0a'.hex #=> 10
'-1234'.hex #=> -4660
'0'.hex #=> 0
'abcdef'.hex #=> 0
5639 5640 5641 5642 |
# File 'lib/source/ruby.rb', line 5639 def hex `var result=parseInt(this.__value__,16)` return `result.toString()=='NaN'?0:result` end |
#include?(obj) ⇒ Boolean
call-seq:
str.include?(other) -> true or false
str.include?(num) -> true or false
Returns true
if str contains the given string or character.
'abcdef'.include?('bc') #=> true
'abcdef'.include?('xy') #=> false
'abcdef'.include?(?c) #=> true
5654 5655 5656 |
# File 'lib/source/ruby.rb', line 5654 def include?(obj) `new(RegExp)(typeof(obj)=='number'?String.fromCharCode(obj):obj.__value__.replace(/([-.*+?^${}()|[\\]\\/\\\\])/g, '\\\\$1')).test(this.__value__)` end |
#inspect ⇒ Object
FIX: Incomplete
5667 5668 5669 |
# File 'lib/source/ruby.rb', line 5667 def inspect `$q('"'+this.__value__.replace(/\\\\/g,'\\\\\\\\').replace(/"/g,'\\\\"')+'"')` end |
#intern ⇒ Object
call-seq:
str.intern -> symbol
str.to_sym -> symbol
Returns the Symbol
corresponding to str, creating the symbol if it did not previously exist. See also Symbol#id2name
.
'abcdef'.intern #=> :abcdef
5680 5681 5682 |
# File 'lib/source/ruby.rb', line 5680 def intern `$s(this.__value__)` end |
#length ⇒ Object
call-seq:
str.length -> integer
str.size -> integer
Returns the number of characters in str.
'abcdef'.length #=> 6
'ab\ncd'.length #=> 5
5693 5694 5695 |
# File 'lib/source/ruby.rb', line 5693 def length `this.__value__.length` end |
#lstrip ⇒ Object
call-seq:
str.lstrip -> string
Returns a copy of str with leading whitespace removed.
' abcdef'.lstrip #=> "abcdef"
'\tabcdef'.lstrip #=> "abcdef"
5709 5710 5711 |
# File 'lib/source/ruby.rb', line 5709 def lstrip `$q(this.__value__.replace(/^\\s*/,''))` end |
#lstrip! ⇒ Object
call-seq:
str.lstrip! -> str
Returns str with leading whitespace removed, or nil
if no changes were made.
s = ' abcdef'
s.lstrip! #=> "abcdef"
s.lstrip! #=> nil
s #=> "abcdef"
5725 5726 5727 5728 5729 |
# File 'lib/source/ruby.rb', line 5725 def lstrip! `var v=this.__value__` `this.__value__=v.replace(/^\\s*/,'')` return `this.__value__==v?nil:this` end |
#match(pattern) ⇒ Object
call-seq:
str.match(pattern) -> matchdata or nil
Converts pattern to a Regexp
(if it isn’t already one), then invokes its match method on str.
'abcdee'.match('(.)\1') #=> #<MatchData:120>
'abcdee'.match('(.)\1')[0] #=> "ee"
'abcdee'.match(/(.)\1/)[0] #=> "ee"
'abcdee'.match('xx') #=> nil
5742 5743 5744 |
# File 'lib/source/ruby.rb', line 5742 def match(pattern) `$r(pattern.__source__||pattern.__value__,pattern.__options__).m$match(this)` end |
#next ⇒ Object
call-seq:
str.next -> string
str.succ -> string
Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case.
If the increment generates a “carry,” the character to the left is also incremented. This process repeats until there is no carry, adding an additional character of the same type as the leftmost alphanumeric, if necessary.
'abcdef'.next #=> 'abcdeg'
'<<kit9>>'.next #=> '<<kit10>>'
'1999zzz'.next #=> '2000aaa'
'ZZZ9999'.next #=> 'AAAA0000'
5766 5767 5768 5769 5770 5771 5772 5773 |
# File 'lib/source/ruby.rb', line 5766 def next `var v=this.__value__` `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}` `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}` `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}` `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}` return `$q(result)` end |
#next! ⇒ Object
call-seq:
str.next! -> str
str.succ! -> str
Returns str with its contents replaced by its successor. See String#next
for details.
5782 5783 5784 5785 5786 5787 5788 5789 5790 |
# File 'lib/source/ruby.rb', line 5782 def next! `var v=this.__value__` `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}` `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}` `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}` `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}` `this.__value__=result` return self end |
#oct ⇒ Object
call-seq:
str.oct -> num
Treats leading characters from str as a string of hexadecimal digits (with an optional sign) and returns the corresponding number. Zero is returned on error.
'0123'.oct #=> 83
'-337'.hex #=> -255
'0'.hex #=> 0
'abcdef'.hex #=> 0
5804 5805 5806 5807 |
# File 'lib/source/ruby.rb', line 5804 def oct `var result=parseInt(this.__value__,8)` return `result.toString()=='NaN'?0:result` end |
#replace(str) ⇒ Object
call-seq:
str.replace(other) -> str
Replaces the contents of str with the contents of other.
s = 'abc'
s.replace('def') #=> "def"
s #=> "def"
5819 5820 5821 |
# File 'lib/source/ruby.rb', line 5819 def replace(str) `this.__value__=str.__value__` end |
#reverse ⇒ Object
call-seq:
str.reverse -> string
Returns a new string with the characters from str in reverse order.
'abcdef'.reverse #=> 'fedcba'
5830 5831 5832 |
# File 'lib/source/ruby.rb', line 5830 def reverse `$q(this.__value__.split('').reverse().join(''))` end |
#reverse! ⇒ Object
call-seq:
str.reverse! -> str
Returns str with its characters reversed.
s = 'abcdef'
s.reverse! #=> 'fedcba'
s #=> 'fedcba'
5844 5845 5846 5847 |
# File 'lib/source/ruby.rb', line 5844 def reverse! `this.__value__=this.__value__.split('').reverse().join('')` return self end |
#rstrip ⇒ Object
call-seq:
str.rstrip -> string
Returns a copy of str with trailing whitespace removed.
'abcdef '.rstrip #=> "abcdef"
'abcdef\r\n'.rstrip #=> "abcdef"
5865 5866 5867 |
# File 'lib/source/ruby.rb', line 5865 def rstrip `$q(this.__value__.replace(/\\s*$/,''))` end |
#rstrip! ⇒ Object
call-seq:
str.rstrip! -> str
Returns str with trailing whitespace removed, or nil
if no changes were made.
s = 'abcdef '
s.rstrip! #=> "abcdef"
s.rstrip! #=> nil
s #=> "abcdef"
5881 5882 5883 5884 5885 |
# File 'lib/source/ruby.rb', line 5881 def rstrip! `var v=this.__value__` `this.__value__=v.replace(/\\s*$/,'')` return `this.__value__==v?nil:this` end |
#size ⇒ Object
call-seq:
str.length -> integer
str.size -> integer
Returns the number of characters in str.
'abcdef'.size #=> 6
'ab\ncd'.size #=> 5
5900 5901 5902 |
# File 'lib/source/ruby.rb', line 5900 def size `this.__value__.length` end |
#slice ⇒ Object
call-seq:
str[num] -> integer or nil
str[num, num] -> string or nil
str[range] -> string or nil
str[regexp] -> string or nil
str[regexp, num] -> string or nil
str[other] -> string or nil
str.slice(num) -> integer or nil
str.slice(num, num) -> string or nil
str.slice(range) -> string or nil
str.slice(regexp) -> string or nil
str.slice(regexp, num) -> string or nil
str.slice(other) -> string or nil
FIX: Incomplete
5919 5920 |
# File 'lib/source/ruby.rb', line 5919 def slice end |
#slice! ⇒ Object
call-seq:
str.slice!(num) -> num or nil
str.slice!(num, num) -> string or nil
str.slice!(range) -> string or nil
str.slice!(regexp) -> string or nil
str.slice!(other) -> string or nil
FIX: Incomplete
5930 5931 |
# File 'lib/source/ruby.rb', line 5930 def slice! end |
#split(pattern = /\s+/, limit = nil) ⇒ Object
FIX: Incomplete
5934 5935 5936 5937 5938 |
# File 'lib/source/ruby.rb', line 5934 def split(pattern = /\s+/, limit = nil) `var a=this.__value__.split(pattern.__value__),result=[]` `for(var i=0,l=a.length;i<l;++i){result.push($q(a[i]));}` return `result` end |
#strip ⇒ Object
call-seq:
str.strip -> string
Returns a copy of str with leading and trailing whitespace removed.
' abcdef '.strip #=> "abcdef"
'\tabcdef\r\n'.strip #=> "abcdef"
5952 5953 5954 |
# File 'lib/source/ruby.rb', line 5952 def strip `$q(this.__value__.replace(/^\\s*|\\s*$/,''))` end |
#strip! ⇒ Object
call-seq:
str.strip! -> str
Returns str with leading and trailing whitespace removed, or nil
if no changes were made.
s = ' abcdef '
s.strip! #=> "abcdef"
s.strip! #=> nil
s #=> "abcdef"
5968 5969 5970 5971 5972 |
# File 'lib/source/ruby.rb', line 5968 def strip! `var v=this.__value__` `this.__value__=v.replace(/^\\s*|\\s*$/,'')` return `this.__value__==v?nil:this` end |
#strip_scripts(evaluate = false) ⇒ Object
call-seq:
str.strip_scripts(evaluate = false) -> string
Returns a copy of str with the contents of any <script>
tags removed. If evaluate is set to true, the stripped scripts will be evaluated.
231 232 233 234 235 236 |
# File 'lib/source/redshift/request.rb', line 231 def strip_scripts(evaluate = false) scripts = '' result = `this.__value__.replace(/<script[^>]*>([\\s\\S]*?)<\\/script>/gi,function(){scripts.__value__+=arguments[1]+'\\n';return '';})` Document.execute_js(scripts) if evaluate return result end |
#succ ⇒ Object
call-seq:
str.next -> string
str.succ -> string
Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case.
If the increment generates a “carry,” the character to the left is also incremented. This process repeats until there is no carry, adding an additional character of the same type as the leftmost alphanumeric, if necessary.
'abcdef'.succ #=> 'abcdeg'
'<<kit9>>'.succ #=> '<<kit10>>'
'1999zzz'.succ #=> '2000aaa'
'ZZZ9999'.succ #=> 'AAAA0000'
6002 6003 6004 6005 6006 6007 6008 6009 |
# File 'lib/source/ruby.rb', line 6002 def succ `var v=this.__value__` `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}` `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}` `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}` `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}` return `$q(result)` end |
#succ! ⇒ Object
call-seq:
str.next! -> str
str.succ! -> str
Returns str with its contents replaced by its successor. See String#next
for details.
6018 6019 6020 6021 6022 6023 6024 6025 6026 |
# File 'lib/source/ruby.rb', line 6018 def succ! `var v=this.__value__` `if(!/[a-zA-Z0-9]/.test(v)){return $q(v);}` `if(/^\\d+$/.test(v)){return $q(''+(+v+1))}` `for(var i=v.length-1,carry=i>=0,result='';i>=0;--i){var c=v[i],lc=/[a-z]/.test(c),uc=/[A-Z]/.test(c),n=/[0-9]/.test(c);if($T(carry)&&(lc||uc||n)){if(lc||uc){if(c=='z'||c=='Z'){result=(lc?'a':'A')+result;carry=i;}else{result=String.fromCharCode(c.charCodeAt()+1)+result;carry=false;};}else{if(c=='9'){result='0'+result;carry=i}else{result=''+(+c+1)+result;carry=false;};};}else{result=c+result;};}` `if($T(carry)){var c=v[carry],insert=/[a-z]/.test(c)?'a':(/[A-Z]/.test(c)?'A':'1');result=result.slice(0,carry)+insert+result.slice(carry,result.length);}` `this.__value__=result` return self end |
#swapcase ⇒ Object
call-seq:
str.swapcase -> string
Returns a copy of str with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase.
'aBc123'.swapcase #=> "AbC123"
6040 6041 6042 |
# File 'lib/source/ruby.rb', line 6040 def swapcase `$q(this.__value__.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();}))` end |
#swapcase! ⇒ Object
call-seq:
str.swapcase! -> str or nil
Returns str with its uppercase alphabetic characters converted to lowercase and its lowercase characters converted to uppercase, or nil
if no changes were made.
s1 = 'abcDEF'
s2 = '123'
s1.swapcase! #=> "ABCdef"
s2.swapcase! #=> nil
s1 #=> "ABCdef"
s2 #=> "123"
6059 6060 6061 6062 6063 |
# File 'lib/source/ruby.rb', line 6059 def swapcase! `var v=this.__value__` `this.__value__=v.replace(/([a-z]+)|([A-Z]+)/g,function($0,$1,$2){return $1?$0.toUpperCase():$0.toLowerCase();})` return `this.__value__==v?nil:this` end |
#to_f ⇒ Object
call-seq:
str.to_f -> float
Returns the result of interpreting leading characters in str as a floating point number, or 0 if there is not a valid number at the start of str.
'1.2345e3'.to_f #=> 1234.5
'98.6 degrees'.to_f #=> 98.6
'abc123'.to_f #=> 0
6076 6077 6078 6079 |
# File 'lib/source/ruby.rb', line 6076 def to_f `var result=parseFloat(this)` return `result.toString()=='NaN'?0:result` end |
#to_i(base = 10) ⇒ Object
call-seq:
str.to_i -> integer
Returns the result of interpreting leading characters in str as an integer of base base, or 0 if there is not a valid number at the start of str.
'12345'.to_i #=> 12345
'76 trombones'.to_i #=> 76
'0a'.to_i #=> 0
'0a'.to_i(16) #=> 10
'abcdef'.to_i #=> 0
'1100101'.to_i(2) #=> 101
'1100101'.to_i(8) #=> 294977
'1100101'.to_i(10) #=> 1100101
'1100101'.to_i(16) #=> 17826049
6098 6099 6100 6101 |
# File 'lib/source/ruby.rb', line 6098 def to_i(base = 10) `var result=parseInt(this,base)` return `result.toString()=='NaN'?0:result` end |
#to_s ⇒ Object
call-seq:
str.to_s -> str
str.to_str -> str
Returns str.
6109 6110 6111 |
# File 'lib/source/ruby.rb', line 6109 def to_s return self end |
#to_str ⇒ Object
call-seq:
str.to_s -> str
str.to_str -> str
Returns str.
6119 6120 6121 |
# File 'lib/source/ruby.rb', line 6119 def to_str return self end |
#to_sym ⇒ Object
call-seq:
str.intern -> symbol
str.to_sym -> symbol
Returns the Symbol
corresponding to str, creating the symbol if it did not previously exist. See also Symbol#id2name
.
'abcdef'.to_sym #=> :abcdef
6132 6133 6134 |
# File 'lib/source/ruby.rb', line 6132 def to_sym `$s(this.__value__)` end |
#upcase ⇒ Object
call-seq:
str.upcase -> string
Returns a copy of str with all lowercase letters replaced with their uppercase counterparts.
'aBCDEf'.upcase #=> "ABCDEF"
6160 6161 6162 |
# File 'lib/source/ruby.rb', line 6160 def upcase `$q(this.__value__.toUpperCase())` end |
#upcase! ⇒ Object
call-seq:
str.upcase! -> str or nil
Returns str with all lowercase letters replaced with their uppercase counterparts, or nil
if no changes were made.
s = 'aBCDEf'
s.upcase! #=> "ABCDEF"
s.upcase! #=> nil
s #=> "ABCDEF"
6176 6177 6178 6179 6180 |
# File 'lib/source/ruby.rb', line 6176 def upcase! `var v=this.__value__` `this.__value__=v.toUpperCase()` return `v==this.__value__?nil:this` end |
#upto(str, &block) ⇒ Object
FIX: Incomplete
6183 6184 |
# File 'lib/source/ruby.rb', line 6183 def upto(str,&block) end |