⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
syntax
/
View File Name :
page-comments_rdoc.ri
U:RDoc::TopLevel[ i I"syntax/comments.rdoc:EFcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[xS:RDoc::Markup::Heading: leveli: textI"Code Comments;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I"6Ruby has two types of comments: inline and block.;T@ o; ;[I"TInline comments start with the
#
character and continue until the ;TI"end of the line:;T@ o:RDoc::Markup::Verbatim;[I"# On a separate line ;TI"+class Foo # or at the end of the line ;TI" # can be indented ;TI" def bar ;TI" end ;TI" end ;T:@format0o; ;[I"SBlock comments start with
=begin
and end with
=end
. ;TI"*Each should start on a separate line.;T@ o;;[I"=begin ;TI" This is ;TI"commented out ;TI" =end ;TI" ;TI"class Foo ;TI" end ;TI" ;TI"=begin some_tag ;TI"this works, too ;TI" =end ;T;0o; ;[I"Q
=begin
and
=end
can not be indented, so this is a ;TI"syntax error:;T@ o;;[ I"class Foo ;TI" =begin ;TI" Will not work ;TI" =end ;TI" end ;T;0S; ; i;I"Magic Comments;T@ o; ;[I"TWhile comments are typically ignored by Ruby, special "magic comments" contain ;TI"8directives that affect how the code is interpreted.;T@ o; ;[I"UTop-level magic comments must start on the first line, or on the second line if ;TI"8the first line looks like
#! shebang line
.;T@ o; ;[I"ENOTE: Magic comments affect only the file in which they appear; ;TI" other files are unaffected.;T@ o;;[ I"## frozen_string_literal: true ;TI" ;TI"var = 'hello' ;TI"var.frozen? # => true ;T;0S; ; i;I"Alternative syntax;T@ o; ;[I"QMagic comments may consist of a single directive (as in the example above). ;TI"XAlternatively, multiple directives may appear on the same line if separated by ";" ;TI"’and wrapped between "-*-" (see Emacs' {file variables}[https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html]).;T@ o;;[ I":# emacs-compatible; -*- coding: big5; mode: ruby -*- ;TI" ;TI"!p 'hello'.frozen? # => true ;TI".p 'hello'.encoding # => #
;T;0S; ; i;I"+encoding+ Directive;T@ o; ;[I"IIndicates which string encoding should be used for string literals, ;TI"3regexp literals and
__ENCODING__
:;T@ o;;[I"# encoding: big5 ;TI" ;TI"'''.encoding # => #
;T;0o; ;[I"Default encoding is UTF-8.;T@ o; ;[I";It must appear in the first comment section of a file.;T@ o; ;[I"9The word "coding" may be used instead of "encoding".;T@ S; ; i;I"&+frozen_string_literal+ Directive;T@ o; ;[I"VIndicates that string literals should be allocated once at parse time and frozen.;T@ o;;[I"## frozen_string_literal: true ;TI" ;TI"3.times do ;TI"3 p 'hello'.object_id # => prints same number ;TI" end ;TI"!p 'world'.frozen? # => true ;T;0o; ;[I"aThe default is false; this can be changed with
--enable=frozen-string-literal
. ;TI"QWithout the directive, or with
# frozen_string_literal: false
, ;TI"Cthe example above would print 3 different numbers and "false".;T@ o; ;[I"VStarting in Ruby 3.0, string literals that are dynamic are not frozen nor reused:;T@ o;;[I"## frozen_string_literal: true ;TI" ;TI"/p "Addition: #{2 + 2}".frozen? # => false ;T;0o; ;[I";It must appear in the first comment section of a file.;T@ S; ; i;I"+warn_indent+ Directive;T@ o; ;[I"[This directive can turn on detection of bad indentation for statements that follow it:;T@ o;;[I" def foo ;TI" end # => no warning ;TI" ;TI"# warn_indent: true ;TI" def bar ;TI"J end # => warning: mismatched indentations at 'end' with 'def' at 6 ;T;0o; ;[I"«Another way to get these warnings to show is by running Ruby with warnings (
ruby -w
). Using a directive to set this false will prevent these warnings to show.;T@ S; ; i;I")+shareable_constant_value+ Directive;T@ o; ;[I"XNote: This directive is experimental in Ruby 3.0 and may change in future releases.;T@ o; ;[I"¦This special directive helps to create constants that hold only immutable objects, or {Ractor-shareable}[rdoc-ref:Ractor@Shareable+and+unshareable+objects] constants.;T@ o; ;[I"RThe directive can specify special treatment for values assigned to constants:;T@ o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"+none+: (default);To;;0;[o; ;[I"O+literal+: literals are implicitly frozen, others must be Ractor-shareable;To;;0;[o; ;[I"2+experimental_everything+: all made shareable;To;;0;[o; ;[I";+experimental_copy+: copy deeply and make it shareable;T@ S; ; i ;I"Mode +none+ (default);T@ o; ;[I"]No special treatment in this mode (as in Ruby 2.x): no automatic freezing and no checks.;T@ o; ;[I"PIt has always been a good idea to deep-freeze constants; Ractor makes this ;TI"Tan even better idea as only the main ractor can access non-shareable constants:;T@ o;;[ I" shareable_constant_value: none ;TI"A = {foo: []} ;TI"A.frozen? # => false ;TI"YRactor.new { puts A } # => can not access non-shareable objects by non-main Ractor. ;T;0S; ; i ;I"Mode +literal+;T@ o; ;[I"MIn "literal" mode, constants assigned to literals will be deeply-frozen:;T@ o;;[I")# shareable_constant_value: literal ;TI"CX = [{foo: []}] # => same as [{foo: [].freeze}.freeze].freeze ;T;0o; ;[I"$Other values must be shareable:;T@ o;;[I")# shareable_constant_value: literal ;TI"?X = Object.new # => cannot assign unshareable object to X ;T;0o; ;[I"qNote that only literals directly assigned to constants, or recursively held in such literals will be frozen:;T@ o;;[ I")# shareable_constant_value: literal ;TI"var = [{foo: []}] ;TI"Dvar.frozen? # => false (assignment was made to local variable) ;TI"8X = var # => cannot assign unshareable object to X ;TI" ;TI"PX = Set[1, 2, {foo: []}].freeze # => cannot assign unshareable object to X ;TI"H # (`Set[...]` is not a literal and ;TI"O # `{foo: []}` is an argument to `Set.[]`) ;T;0o; ;[I"1The method Module#const_set is not affected.;T@ S; ; i ;I"#Mode +experimental_everything+;T@ o; ;[I"GIn this mode, all values assigned to constants are made shareable.;T@ o;;[I"9# shareable_constant_value: experimental_everything ;TI" FOO = Set[1, 2, {foo: []}] ;TI"/# same as FOO = Ractor.make_sharable(...) ;TI"D# OR same as `FOO = Set[1, 2, {foo: [].freeze}.freeze].freeze` ;TI" ;TI"var = [{foo: []}] ;TI"Dvar.frozen? # => false (assignment was made to local variable) ;TI"5X = var # => calls `Ractor.make_shareable(var)` ;TI"var.frozen? # => true ;T;0o; ;[I"GThis mode is "experimental", because it might be error prone, for ;TI"Jexample by deep-freezing the constants of an external resource which ;TI"could cause errors:;T@ o;;[I"9# shareable_constant_value: experimental_everything ;TI"#FOO = SomeGem::Something::FOO ;TI"+# => deep freezes the gem's constant! ;T;0o; ;[I"IThis will be revisited before Ruby 3.1 to either allow `everything` ;TI"$or to instead remove this mode.;T@ o; ;[I"1The method Module#const_set is not affected.;T@ S; ; i ;I"Mode +experimental_copy+;T@ o; ;[I"JIn this mode, all values assigned to constants are deeply copied and ;TI"Emade shareable. It is safer mode than +experimental_everything+.;T@ o;;[I"9# shareable_constant_value: experimental_everything ;TI"var = [{foo: []}] ;TI"Dvar.frozen? # => false (assignment was made to local variable) ;TI"AX = var # => calls `Ractor.make_shareable(var, copy: true)` ;TI"var.frozen? # => false ;TI"#Ractor.shareable?(X) #=> true ;TI",var.object_id == X.object_id #=> false ;T;0o; ;[I"HThis mode is "experimental" and has not been discussed thoroughly. ;TI"CThis will be revisited before Ruby 3.1 to either allow `copy` ;TI"$or to instead remove this mode.;T@ o; ;[I"1The method Module#const_set is not affected.;T@ S; ; i ;I" Scope;T@ o; ;[I"@This directive can be used multiple times in the same file:;T@ o;;[I" shareable_constant_value: none ;TI"A = {foo: []} ;TI"A.frozen? # => false ;TI"YRactor.new { puts A } # => can not access non-shareable objects by non-main Ractor. ;TI" ;TI")# shareable_constant_value: literal ;TI"B = {foo: []} ;TI"B.frozen? # => true ;TI"B[:foo].frozen? # => true ;TI" ;TI"ZC = [Object.new] # => cannot assign unshareable object to C (Ractor::IsolationError) ;TI" ;TI"D = [Object.new.freeze] ;TI"D.frozen? # => true ;TI" ;TI"9# shareable_constant_value: experimental_everything ;TI"E = Set[1, 2, Object.new] ;TI"E.frozen? # => true ;TI" E.all(&:frozen?) # => true ;T;0o; ;[I"TThe directive affects only subsequent constants and only for the current scope:;T@ o;;[I"module Mod ;TI"+ # shareable_constant_value: literal ;TI" A = [1, 2, 3] ;TI" module Sub ;TI" B = [4, 5] ;TI" end ;TI" end ;TI" ;TI"C = [4, 5] ;TI" ;TI"module Mod ;TI" D = [6] ;TI" end ;TI";p Mod::A.frozen?, Mod::Sub::B.frozen? # => true, true ;TI"2p C.frozen?, Mod::D.frozen? # => false, false;T;0: @file@:0@omit_headings_from_table_of_contents_below0