Class: Symbol
- Includes:
- Comparable
- Defined in:
- ext/enterprise_script_service/mruby/src/symbol.c,
ext/enterprise_script_service/mruby/mrblib/symbol.rb,
ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
Overview
********************************************************************
<code>Symbol</code> objects represent names and some strings
inside the Ruby
interpreter. They are generated using the <code>:name</code> and
<code>:"string"</code> literals
syntax, and by the various <code>to_sym</code> methods. The same
<code>Symbol</code> object will be created for a given name or string
for the duration of a program's execution, regardless of the context
or meaning of that name. Thus if <code>Fred</code> is a constant in
one context, a method in another, and a class in a third, the
<code>Symbol</code> <code>:Fred</code> will be the same object in
all three contexts.
module One
class Fred
end
$f1 = :Fred
end
module Two
Fred = 1
$f2 = :Fred
end
def Fred()
end
$f3 = :Fred
$f1.object_id #=> 2514190
$f2.object_id #=> 2514190
$f3.object_id #=> 2514190
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 'ext/enterprise_script_service/mruby/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 'ext/enterprise_script_service/mruby/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 'ext/enterprise_script_service/mruby/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 'ext/enterprise_script_service/mruby/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 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 68 def empty? self.length == 0 end |
#to_proc ⇒ Object
2 3 4 5 6 |
# File 'ext/enterprise_script_service/mruby/mrblib/symbol.rb', line 2 def to_proc ->(obj,*args,&block) do obj.__send__(self, *args, &block) end end |
#upcase ⇒ Object
call-seq:
sym.upcase -> symbol
Same as sym.to_s.upcase.intern
.
32 33 34 |
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 32 def upcase (self.to_s.upcase! || self).to_sym end |