Class: Symbol
- Inherits:
-
Object
- Object
- Symbol
- Includes:
- Comparable
- Defined in:
- mrblib/symbol.rb,
mrbgems/mruby-symbol-ext/mrblib/symbol.rb
Instance Method Summary collapse
-
#capitalize ⇒ Object
call-seq: sym.capitalize -> symbol.
-
#casecmp(other) ⇒ Object
call-seq: sym.casecmp(other) -> -1, 0, +1 or nil.
-
#casecmp?(sym) ⇒ Boolean
call-seq: sym.casecmp?(other) -> true, false, or nil.
-
#downcase ⇒ Object
call-seq: sym.downcase -> symbol.
-
#empty? ⇒ Boolean
call-seq: sym.empty? -> true or false.
- #to_proc ⇒ Object
-
#upcase ⇒ Object
call-seq: sym.upcase -> symbol.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?, #clamp
Instance Method Details
#capitalize ⇒ Object
call-seq: sym.capitalize -> symbol
Same as sym.to_s.capitalize.intern.
12 13 14 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 12 def capitalize (self.to_s.capitalize! || self).to_sym end |
#casecmp(other) ⇒ Object
call-seq: sym.casecmp(other) -> -1, 0, +1 or nil
Case-insensitive version of Symbol#<=>.
42 43 44 45 46 47 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 42 def casecmp(other) return nil unless other.kind_of?(Symbol) lhs = self.to_s; lhs.upcase! rhs = other.to_s.upcase lhs <=> rhs end |
#casecmp?(sym) ⇒ Boolean
call-seq: sym.casecmp?(other) -> true, false, or nil
Returns true if sym and other_sym are equal after case folding, false if they are not equal, and nil if other_sym is not a string.
56 57 58 59 60 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 56 def casecmp?(sym) c = self.casecmp(sym) return nil if c.nil? return c == 0 end |
#downcase ⇒ Object
call-seq: sym.downcase -> symbol
Same as sym.to_s.downcase.intern.
22 23 24 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 22 def downcase (self.to_s.downcase! || self).to_sym end |
#empty? ⇒ Boolean
call-seq: sym.empty? -> true or false
Returns that sym is :"" or not.
68 69 70 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 68 def empty? self.length == 0 end |
#to_proc ⇒ Object
2 3 4 5 6 7 |
# File 'mrblib/symbol.rb', line 2 def to_proc mid = self ->(obj,*args,**opts,&block) do obj.__send__(mid, *args, **opts, &block) end end |
#upcase ⇒ Object
call-seq: sym.upcase -> symbol
Same as sym.to_s.upcase.intern.
32 33 34 |
# File 'mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 32 def upcase (self.to_s.upcase! || self).to_sym end |