source: EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-symbol-ext/mrblib/symbol.rb@ 439

Last change on this file since 439 was 439, checked in by coas-nagasima, 4 years ago

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1.3 KB
Line 
1class Symbol
2 include Comparable
3
4 alias intern to_sym
5
6 ##
7 # call-seq:
8 # sym.capitalize -> symbol
9 #
10 # Same as <code>sym.to_s.capitalize.intern</code>.
11
12 def capitalize
13 (self.to_s.capitalize! || self).to_sym
14 end
15
16 ##
17 # call-seq:
18 # sym.downcase -> symbol
19 #
20 # Same as <code>sym.to_s.downcase.intern</code>.
21
22 def downcase
23 (self.to_s.downcase! || self).to_sym
24 end
25
26 ##
27 # call-seq:
28 # sym.upcase -> symbol
29 #
30 # Same as <code>sym.to_s.upcase.intern</code>.
31
32 def upcase
33 (self.to_s.upcase! || self).to_sym
34 end
35
36 ##
37 # call-seq:
38 # sym.casecmp(other) -> -1, 0, +1 or nil
39 #
40 # Case-insensitive version of <code>Symbol#<=></code>.
41
42 def casecmp(other)
43 return nil unless other.kind_of?(Symbol)
44 lhs = self.to_s; lhs.upcase!
45 rhs = other.to_s.upcase
46 lhs <=> rhs
47 end
48
49 ##
50 # call-seq:
51 # sym.casecmp?(other) -> true, false, or nil
52 #
53 # Returns true if sym and other_sym are equal after case folding,
54 # false if they are not equal, and nil if other_sym is not a string.
55
56 def casecmp?(sym)
57 c = self.casecmp(sym)
58 return nil if c.nil?
59 return c == 0
60 end
61
62 #
63 # call-seq:
64 # sym.empty? -> true or false
65 #
66 # Returns that _sym_ is :"" or not.
67
68 def empty?
69 self.length == 0
70 end
71
72end
Note: See TracBrowser for help on using the repository browser.