Tokenize string
returning the Ruby object
Create a new TreeBuilder
instance
Create a new Psych::Emitter
that writes to io
.
Emit a scalar with value
, anchor
, tag
, and a plain
or quoted
string type with style
.
Get the output style, canonical or not.
Set
the output style to canonical, or not.
Get the indentation level.
Set
the indentation level to level
. The level must be less than 10 and greater than 1.
Start streaming using encoding
@api private
Raised by exit
to initiate the termination of the script.
Raised when encountering Ruby code with an invalid syntax.
eval("1+1=2")
raises the exception:
SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
SystemCallError
is the base class for all low-level platform-dependent errors.
The errors available on the current platform are subclasses of SystemCallError
and are defined in the Errno
module.
File.open("does/not/exist")
raises the exception:
Errno::ENOENT: No such file or directory - does/not/exist
Symbol
objects represent named identifiers inside the Ruby interpreter.
You can create a Symbol object explicitly with:
The same Symbol
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 Fred
is a constant in one context, a method in another, and a class in a third, the Symbol
:Fred
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
Constant, method, and variable names are returned as symbols:
module One Two = 2 def three; 3 end @four = 4 @@five = 5 $six = 6 end seven = 7 One.constants # => [:Two] One.instance_methods(true) # => [:three] One.instance_variables # => [:@four] One.class_variables # => [:@@five] global_variables.grep(/six/) # => [:$six] local_variables # => [:seven]
Symbol
objects are different from String
objects in that Symbol
objects represent identifiers, while String
objects represent text or data.
First, what’s elsewhere. Class Symbol:
Inherits from class Object.
Includes module Comparable.
Here, class Symbol provides methods that are useful for:
::all_symbols
Returns an array of the symbols currently in Ruby’s symbol table.
empty?
Returns true
if self.length
is zero; false
otherwise.
end_with?
Returns true
if symbol ends with any of the given strings.
start_with?
Returns true
if symbol starts with any of the given strings.
Returns -1, 0, or 1 as a given symbol is smaller than, equal to, or larger than symbol.
Returns true
if a given symbol has the same content and encoding.
casecmp
Ignoring case, returns -1, 0, or 1 as a given symbol is smaller than, equal to, or larger than symbol.
casecmp?
Returns true
if symbol is equal to a given symbol after Unicode case folding; false
otherwise.
capitalize
Returns symbol with the first character upcased and all other characters downcased.
downcase
Returns symbol with all characters downcased.
inspect
Returns the string representation of self
as a symbol literal.
name
Returns the frozen string corresponding to symbol.
swapcase
Returns symbol with all upcase characters downcased and all downcase characters upcased.
upcase
Returns symbol with all characters upcased.