Ironruby-quick learning of basic Ruby knowledge in half an hour

Source: Internet
Author: User
ArticleDirectory
    • Variables
    • Conditions
    • Loops
    • Error Handling
    • Methods
    • Classes
    • Using code from other files

In the previous blogs, I introduced some ironruby-related content, because ironruby is in ruby. net, so its basic syntax and usage are similar to Ruby. To learn how to use ironruby, we must first quickly understand how to use ruby, this article mainly introduces some basic Ruby knowledge, which is also the main things I have used over the past few days. I hope it will be helpful to beginners.

Variables

Defining variables is simple. You only need to write a lower-case code name followed by the equal sign and value, as shown in figure

 
STR = "hello"
Num = 1
Arr = [1, 2, 3]
Conditions
    • If XXX then XXX elseif XXX then XXX end
    • Title = "login" If (Title = "")
    • Unless (Password = "") the xxx end
Loops
    • While XXX do XXX end
    • Until XXX do XXX end
    • For item in XXX do XXX end
    • 10. Times do | I | print I end
    • A. Each do | item | puts item end
Error Handling
 
Begin
# Something risky
Rescue someexception
Xxx
Rescue exception
Xxx
Rescue
Xxx
End
Methods
 
Def add (A, B)
A + B
End
 


    • The Return Value of the method can be returned through return XXX, or directly write the value to be returned at the end of the method.
    • Result1 = add (1, 2) or result2 = Add 1, 2
Classes
 
Class testapplication
Def initialize # Constructor
Self. runing = false # assign values to attributes
End

Attr_accessor: runing # Attribute attr_reader attr_writer

@ Instance = nil # class variable
@Instance_variable = 0 # instance variable

Def self. Instance
@ Instance = self. New if @ instance = Nil
@ Instance # function return Singleton
End

 

# Instance method
Def run

Return if self. runing
Xxx
Self. runing = true
End

 
# Class methods
Def self. say_hello
Puts "hello"
End
 



End

 
 
    • Generate testapplication. New
    • UseSuperCall the parent class method. If the parameters are the same, the parameter can be left blank.
Using code from other files
    • $ Load_path <'d:/gzj/openexpressapp/tool/opentest/dll'
      Require "Microsoft. visualstudio. testtools. uitesting. dll"
    • Require "utils/find_control_helper.rb"

 

Recommended:Online e-books you may need

Agile individual Sina microjournal: http://kan.weibo.com/kan/3483302195814612

 You are welcome to reprint it. Please note: Reprinted fromAgile personal website

 

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.