Class: Symbol

Inherits:
Object show all
Includes:
Comparable
Defined in:
ext/enterprise_script_service/mruby/src/symbol.c,
ext/enterprise_script_service/mruby/lib/mruby-core-ext.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

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, #clamp

Instance Method Details

#capitalizeObject

call-seq:

sym.capitalize  -> symbol

Same as sym.to_s.capitalize.intern.



18
19
20
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 18

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#<=>.



48
49
50
51
52
53
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 48

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.

Returns:

  • (Boolean)


62
63
64
65
66
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 62

def casecmp?(sym)
  c = self.casecmp(sym)
  return nil if c.nil?
  return c == 0
end

#downcaseObject

call-seq:

sym.downcase  -> symbol

Same as sym.to_s.downcase.intern.



28
29
30
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 28

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.

Returns:

  • (Boolean)


74
75
76
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 74

def empty?
  self.length == 0
end

#to_procObject

Compatible with 1.9 on 1.8



40
41
42
# File 'ext/enterprise_script_service/mruby/lib/mruby-core-ext.rb', line 40

def to_proc
  proc { |obj, *args| obj.send(self, *args) }
end

#upcaseObject

call-seq:

sym.upcase    -> symbol

Same as sym.to_s.upcase.intern.



38
39
40
# File 'ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb', line 38

def upcase
  (self.to_s.upcase! || self).to_sym
end