What is Ruby?

Source: Internet
Author: User

Keywords
Def UNDEF method definition
Module Definition
Class Definition
Defined? Check type
Conditional statement if, then, else, elsif, case, when, unless
Loop statements for, in, while, until, next, break, do, redo, retry, yield
Logical judgment not, And, or
Logical or null values: True, false, Nil
Exception Handling rescue, ensure
Reference super, self
Embedded Module begin end
Start/end of a block
File-related _ file _ line _
Return Method
Alias alias

Symbol
; Used to separate multiple statements
() Include the parameter list when defining a method
, Separate multiple parameters
. Separate the object from its method.
: The symbol used by the domain to separate the (module) class from its constant.

Operator
[] [] = Array subscript, array assignment
** Chengming
!~ +-Non, non-bit, one dollar plus negative number
*/% Multiplication and division
+-Subtraction
>>< Shift right to left
& Bit and
^ | Bitwise XOR or
<=<>>= Less than or equal to less than or greater than and
<==>======== ~ ! = !~ Equality judgment
& Short circuit and
| Short circuit or
The start and end of the... area, and the second does not include the end.
? : Ternary conditional Operator

Global variables start with $.ProgramBefore initialization, the global variable has a special value nil.
Special variables starting with $ and with a single character are listed here. for example, $ contains the process ID of the Ruby interpreter, which is read-only. here are the main system variables and their meanings (details can be found in the ruby reference manual ):
$! Last error message
$ @ Error location
$ _ Gets recently read string
$. Number of lines recently read by the interpreter (line number)
$ & The latest string matching the Regular Expression
$ ~ Last match as a child expression group
$ N the nth subexpression (and $ ~ [N] Same)
$ = Case-insensitive flag
$/Input record Separator
$ \ Output record Separator
$0 Ruby script file name
$ * Command line parameters
$ Interpreter process ID
$? The last sub-process exited

= Begin

Example: WIN32API operations

= End

Require 'dl'
USER32 = DL. dlopen ("USER32 ")
Mb_okcancel = 1
Message_box = USER32 ['messageboxa ', 'ilssi']
R, RS = message_box.call (0, 'OK? ', 'Please confirm', mb_okcancel)
Case R
When 1
Print ("OK! \ N ")
When 2
Print ("Cancel! \ N ")
End

System ($ * [0]) # command line receiving parameter $ * [0] global variable

File. Open ('C: \ Boot. ini '). ecah do | Line |; puts line; end # Read all content

Arr = file. readlines ('C: \ Boot. ini '); puts arr [0]) # Read-Only first line

File. Open ('C: \ Boot. ini ') Do | F1 | # Another method, read-only the first line
While line = f1.gets
Puts line
Break
End
End

# Writing files

File. New ('C: \ 1.txt ', "W"). Puts 'message'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.