Ruby syntax Summary

Source: Internet
Author: User
No function, with a half-day time to get the environment, with a half-day time familiar syntax, the function can be self-checked manual function query page in the http://www.rubycentral.com/ref/index.html function library official station in http://www.ruby-lang.org/
Write tools use http://homepage2.nifty.com/sakazuki/rde_e.htmlclass A in win
Def initialize (name, age) # Initialization
@ Name = Name;
@ Age = age;
Puts "I am parent ";
End
End
Class A # add methods directly in the class
Def ()
Return @ name;
End
End
# Na = A. New ('aaa', ''); # reputation
# Puts na. to_s # obtain the class ID
# Puts na. Inspect #
# Puts na. ();
Class B <
Def initialize (name = '', age = '')
Super (name, age); # initialize the Class Method
End
Def ABC ()
Puts "I am child! ";
End
End
# Def na. To () # overload
# Return "456789 ";
# End
# Puts na. ();
# B = B. New ();
# B. ABC;
 
# Module usage
Module M
Def BM
B = B. New ();
Return "SADF ";
End
End
# Require "M ";
Include m;
M. bm ();
# Module end
Begin
# Execution Program
Rescue # exception
Retry # re-Execute begin
Ensure # execute if any exception occurs
End
#
# Puts M. bm ();
# B. ABC ();
# Include m;
# Object;
# B. ABC ();
I = 30;
Case I;
When 0... 5
Print '1 ';
When 6... 20
Print '2 ';
When 11... 20
Print '3 ';
End
= Begin comments
Retry back to the beginning of the loop
Yield indicates block call
While (I <19)
If I = 3
Puts ('y ');
# End
# Unless I = 3 # Run as false
# Puts ('n ');
# End
# I = I + 1;
End
= End
Exit (1 );
Until I <19 # Run as false
Puts I;
I = I + 1;
End
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.