IO::ARGF.new(ARGV, STDIN)
((ARGV_UNSAFE + 1).to_slice(ARGC_UNSAFE - 1)).map do |c_str|
String.new(c_str)
end
String.new(ARGV_UNSAFE.value)
FileDescriptorIO.new(2, (LibC.isatty(2)) == 0, true)
FileDescriptorIO.new(0, blocking: (LibC.isatty(0)) == 0, edge_triggerable: true)
(FileDescriptorIO.new(1, (LibC.isatty(1)) == 0, true)).tap(&.flush_on_newline = true)
Terminates execution immediately, printing message to STDERR and then calling .exit(status).
Registers the given Proc for execution when the program exits.
Terminates execution immediately, returning the given status code to the invoking environment.
Repeatedly executes the block.
Prints a series of expressions together with their values.
Defines a struct with the given name and properties.
TODO: this doesn't work if a Call has a block or named arguments...
Terminates execution immediately, printing message to STDERR and
then calling .exit(status).
Registers the given Proc for execution when the program exits.
If multiple handlers are registered, they are executed in reverse order of registration.
def do_at_exit(str1)
at_exit { print str1 }
end
at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit
Produces:
goodbye cruel worldTerminates execution immediately, returning the given status code to the invoking environment.
Registered .at_exit procs are executed.
Repeatedly executes the block.
loop do
print "Input: "
line = gets
break unless line
# ...
endPrints a series of expressions together with their values. Useful for print style debugging.
a = 1
pp a # prints "a = 1"
pp [1, 2, 3].map(&.to_s) # prints "[1, 2, 3].map(&.to_s) = ["1", "2", "3"]Defines a struct with the given name and properties.
The generated struct has a constructor with the given properties in the same order as declared. The struct only provides getters, not setters, making it immutable by default.
You can pass a block to this macro, that will be inserted inside the struct definition.
record Point, x, y
point = Point.new 1, 2
point.to_s #=> "Point(@x=1, @y=2)"
An example with the block version:
record Person, first_name, last_name do
def full_name
"#{first_name} #{last_name}"
end
end
person = Person.new "John", "Doe"
person.full_name #=> "John Doe"TODO: this doesn't work if a Call has a block or named arguments... yet