Methods

chop   chop!   delete   delete!   each_char   end_regexp   is_binary_data?   is_complex_yaml?   iseuc   issjis   isutf8   jcount   jlength   jsize   kconv   mbchar?   quote   squeeze   squeeze!   succ   succ!   to_d   to_yaml   toeuc   tojis   tosjis   toutf16   toutf8   tr   tr!   tr_s   tr_s!   yaml_new  

Constants

PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]'
PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n')
RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n')
RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')
SUCC = {}
HashCache = {}
TrPatternCache = {}
DeletePatternCache = {}
SqueezePatternCache = {}

External Aliases

succ! -> original_succ!
succ -> original_succ

Public Class methods

[Source]

     # File yaml/rubytypes.rb, line 148
148:     def String.yaml_new( klass, tag, val )
149:         val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
150:         val = { 'str' => val } if String === val
151:         if Hash === val
152:             s = klass.allocate
153:             # Thank you, NaHi
154:             String.instance_method(:initialize).
155:                   bind(s).
156:                   call( val.delete( 'str' ) )
157:             val.each { |k,v| s.instance_variable_set( k, v ) }
158:             s
159:         else
160:             raise YAML::TypeError, "Invalid String: " + val.inspect
161:         end
162:     end

Public Instance methods

[Source]

     # File jcode.rb, line 196
196:   def chop
197:     (str = self.dup).chop! or str
198:   end

[Source]

     # File jcode.rb, line 192
192:   def chop!
193:     self.gsub!(/(?:.|\r?\n)\z/, '')
194:   end

[Source]

     # File jcode.rb, line 156
156:   def delete(del)
157:     (str = self.dup).delete!(del) or str
158:   end

[Source]

     # File jcode.rb, line 151
151:   def delete!(del)
152:     return nil if del == ""
153:     self.gsub!(DeletePatternCache[del] ||= /[#{_regex_quote(del)}]+/, '')
154:   end

[Source]

     # File jcode.rb, line 209
209:   def each_char
210:     if block_given?
211:       scan(/./m) do |x|
212:         yield x
213:       end
214:     else
215:       scan(/./m)
216:     end
217:   end

[Source]

    # File jcode.rb, line 59
59:   def end_regexp
60:     case $KCODE[0]
61:     when ?s, ?S
62:       /#{PATTERN_SJIS}$/on
63:     when ?e, ?E
64:       /#{PATTERN_EUC}$/on
65:     when ?u, ?U
66:       /#{PATTERN_UTF8}$/on
67:     else
68:       /.$/on
69:     end
70:   end

[Source]

     # File yaml/rubytypes.rb, line 145
145:     def is_binary_data?
146:         ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
147:     end

[Source]

     # File yaml/rubytypes.rb, line 142
142:     def is_complex_yaml?
143:         to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
144:     end

is Encoding

[Source]

     # File kconv.rb, line 217
217:   def iseuc
218:     Kconv.iseuc( self )
219:   end

[Source]

     # File kconv.rb, line 221
221:   def issjis
222:     Kconv.issjis( self )
223:   end

[Source]

     # File kconv.rb, line 225
225:   def isutf8
226:     Kconv.isutf8( self )
227:   end

[Source]

     # File jcode.rb, line 205
205:   def jcount(str)
206:     self.delete("^#{str}").jlength
207:   end

[Source]

     # File jcode.rb, line 200
200:   def jlength
201:     self.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
202:   end
jsize()

Alias for jlength

[Source]

     # File kconv.rb, line 195
195:   def kconv(out_code, in_code=Kconv::AUTO)
196:     Kconv::kconv(self, out_code, in_code)
197:   end

[Source]

    # File jcode.rb, line 46
46:   def mbchar?
47:     case $KCODE[0]
48:     when ?s, ?S
49:       self =~ RE_SJIS
50:     when ?e, ?E
51:       self =~ RE_EUC
52:     when ?u, ?U
53:       self =~ RE_UTF8
54:     else
55:       nil
56:     end
57:   end

[Source]

     # File mkmf.rb, line 130
130:   def quote
131:     /\s/ =~ self ? "\"#{self}\"" : self
132:   end

[Source]

     # File jcode.rb, line 171
171:   def squeeze(del=nil)
172:     (str = self.dup).squeeze!(del) or str
173:   end

[Source]

     # File jcode.rb, line 160
160:   def squeeze!(del=nil)
161:     return nil if del == ""
162:     pattern =
163:       if del
164:         SqueezePatternCache[del] ||= /([#{_regex_quote(del)}])\1+/
165:       else
166:         /(.|\n)\1+/
167:       end
168:     self.gsub!(pattern, '\1')
169:   end

[Source]

    # File jcode.rb, line 92
92:   def succ
93:     str = self.dup
94:     str.succ! or str
95:   end

[Source]

    # File jcode.rb, line 78
78:   def succ!
79:     reg = end_regexp
80:     if self =~ reg
81:       succ_table = SUCC[$KCODE[0,1].downcase]
82:       begin
83:         self[-1] += succ_table[self[-1]]
84:         self[-2] += 1 if self[-1] == 0
85:       end while self !~ reg
86:       self
87:     else
88:       original_succ!
89:     end
90:   end

[Source]

    # File bigdecimal/util.rb, line 27
27:   def to_d
28:     BigDecimal(self)
29:   end

[Source]

     # File yaml/rubytypes.rb, line 163
163:         def to_yaml( opts = {} )
164:                 YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do |out|
165:             if is_binary_data?
166:                 out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
167:             elsif to_yaml_properties.empty?
168:                 out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style )
169:             else
170:                 out.map( taguri, to_yaml_style ) do |map|
171:                     map.add( 'str', "#{self}" )
172:                     to_yaml_properties.each do |m|
173:                         map.add( m, instance_variable_get( m ) )
174:                     end
175:                 end
176:             end
177:         end
178:         end

[Source]

     # File kconv.rb, line 203
203:   def toeuc
204:     ::NKF::nkf('-e', self)
205:   end

to Encoding

[Source]

     # File kconv.rb, line 200
200:   def tojis
201:     ::NKF::nkf('-j', self)
202:   end

[Source]

     # File kconv.rb, line 206
206:   def tosjis
207:     ::NKF::nkf('-s', self)
208:   end

[Source]

     # File kconv.rb, line 212
212:   def toutf16
213:     ::NKF::nkf('-w16', self)
214:   end

[Source]

     # File kconv.rb, line 209
209:   def toutf8
210:     ::NKF::nkf('-w', self)
211:   end

[Source]

     # File jcode.rb, line 147
147:   def tr(from, to)
148:     (str = self.dup).tr!(from, to) or str
149:   end

[Source]

     # File jcode.rb, line 133
133:   def tr!(from, to)
134:     return nil if from == ""
135:     return self.delete!(from) if to == ""
136: 
137:     pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/
138:     if from[0] == ?^
139:       last = /.$/.match(to)[0]
140:       self.gsub!(pattern, last)
141:     else
142:       h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
143:       self.gsub!(pattern) do |c| h[c] end
144:     end
145:   end

[Source]

     # File jcode.rb, line 188
188:   def tr_s(from, to)
189:     (str = self.dup).tr_s!(from,to) or str
190:   end

[Source]

     # File jcode.rb, line 175
175:   def tr_s!(from, to)
176:     return self.delete!(from) if to.length == 0
177: 
178:     pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1+/
179:     if from[0] == ?^
180:       last = /.$/.match(to)[0]
181:       self.gsub!(pattern, last)
182:     else
183:       h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
184:       self.gsub!(pattern) do h[$1] end
185:     end
186:   end

Search

Google

Ruby API Docs

Links